2024-07-05 13:29:13 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2024-12-05 16:16:30 +01:00
|
|
|
* Class responsible for initializing Event Bridge for ActivityPub.
|
2024-07-05 13:29:13 +02:00
|
|
|
*
|
|
|
|
* The setup class provides function for checking if this plugin should be activated.
|
|
|
|
* It detects supported event plugins and provides all setup hooks and filters.
|
|
|
|
*
|
2024-12-05 16:16:30 +01:00
|
|
|
* @package Event_Bridge_For_ActivityPub
|
2024-07-05 13:29:13 +02:00
|
|
|
* @since 1.0.0
|
2024-08-01 20:08:35 +02:00
|
|
|
* @license AGPL-3.0-or-later
|
2024-07-05 13:29:13 +02:00
|
|
|
*/
|
|
|
|
|
2024-12-05 16:16:30 +01:00
|
|
|
namespace Event_Bridge_For_ActivityPub;
|
2024-07-05 13:29:13 +02:00
|
|
|
|
2024-09-28 13:14:10 +02:00
|
|
|
// Exit if accessed directly.
|
|
|
|
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
|
|
|
|
2024-12-08 21:57:53 +01:00
|
|
|
use Event_Bridge_For_ActivityPub\ActivityPub\Collection\Event_Sources as Event_Sources_Collection;
|
|
|
|
use Event_Bridge_For_ActivityPub\ActivityPub\Handler;
|
2024-12-05 16:16:30 +01:00
|
|
|
use Event_Bridge_For_ActivityPub\Admin\Event_Plugin_Admin_Notices;
|
|
|
|
use Event_Bridge_For_ActivityPub\Admin\General_Admin_Notices;
|
|
|
|
use Event_Bridge_For_ActivityPub\Admin\Health_Check;
|
|
|
|
use Event_Bridge_For_ActivityPub\Admin\Settings_Page;
|
2024-12-11 23:09:12 +01:00
|
|
|
use Event_Bridge_For_ActivityPub\Admin\User_Interface;
|
2024-12-05 16:16:30 +01:00
|
|
|
use Event_Bridge_For_ActivityPub\Integrations\Event_Plugin;
|
2024-07-05 13:29:13 +02:00
|
|
|
|
2024-12-15 13:42:57 +01:00
|
|
|
use function Activitypub\is_user_type_disabled;
|
|
|
|
|
2024-07-05 13:29:13 +02:00
|
|
|
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Setup.
|
2024-12-15 13:44:57 +01:00
|
|
|
|
2024-12-05 16:16:30 +01:00
|
|
|
* This class is responsible for initializing Event Bridge for ActivityPub.
|
2024-07-05 13:29:13 +02:00
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
*/
|
|
|
|
class Setup {
|
|
|
|
/**
|
|
|
|
* Keep the information whether the ActivityPub plugin is active.
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
|
|
|
protected $activitypub_plugin_is_active = false;
|
|
|
|
|
2024-09-11 13:55:37 +02:00
|
|
|
/**
|
|
|
|
* Keep the current version of the current ActivityPub plugin.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $activitypub_plugin_version = '';
|
|
|
|
|
2024-07-05 13:29:13 +02:00
|
|
|
/**
|
|
|
|
* Holds an array of the currently activated supported event plugins.
|
|
|
|
*
|
2024-09-11 00:38:21 +02:00
|
|
|
* @var Event_Plugin[]
|
2024-07-05 13:29:13 +02:00
|
|
|
*/
|
|
|
|
protected $active_event_plugins = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor for the Setup class.
|
|
|
|
*
|
|
|
|
* Initializes and sets up various components of the plugin.
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
*/
|
|
|
|
protected function __construct() {
|
2024-09-24 16:24:31 +02:00
|
|
|
$this->activitypub_plugin_is_active = defined( 'ACTIVITYPUB_PLUGIN_VERSION' ) ||
|
|
|
|
is_plugin_active( 'activitypub/activitypub.php' );
|
2024-09-21 11:00:33 +02:00
|
|
|
// BeforeFirstRelease: decide whether we want to do anything at all when ActivityPub plugin is note active.
|
2024-09-11 13:55:37 +02:00
|
|
|
// if ( ! $this->activitypub_plugin_is_active ) {
|
2024-12-05 16:16:30 +01:00
|
|
|
// deactivate_plugins( EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_FILE );
|
2024-09-11 13:55:37 +02:00
|
|
|
// return;
|
|
|
|
// }.
|
2024-09-24 16:24:31 +02:00
|
|
|
$this->activitypub_plugin_version = self::get_activitypub_plugin_version();
|
2024-12-12 23:24:36 +01:00
|
|
|
add_action( 'plugins_loaded', array( $this, 'setup_hooks' ) );
|
2024-07-05 13:29:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The single instance of the class.
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
* @var ?self|null The instance of the class.
|
|
|
|
*/
|
|
|
|
private static $instance = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the instance of the Singleton class.
|
|
|
|
*
|
|
|
|
* If an instance does not exist, it creates one; otherwise, it returns the existing instance.
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
*
|
|
|
|
* @return self The instance of the class.
|
|
|
|
*/
|
|
|
|
public static function get_instance(): self {
|
|
|
|
if ( null === self::$instance ) {
|
|
|
|
self::$instance = new self();
|
|
|
|
}
|
|
|
|
|
|
|
|
return self::$instance;
|
|
|
|
}
|
|
|
|
|
2024-09-24 16:24:31 +02:00
|
|
|
/**
|
|
|
|
* LooksUp the current version of the ActivityPub.
|
|
|
|
*
|
|
|
|
* @return string The semantic Version.
|
|
|
|
*/
|
|
|
|
private static function get_activitypub_plugin_version(): string {
|
|
|
|
if ( defined( 'ACTIVITYPUB_PLUGIN_VERSION' ) ) {
|
|
|
|
return constant( 'ACTIVITYPUB_PLUGIN_VERSION' );
|
|
|
|
}
|
2024-12-12 23:24:36 +01:00
|
|
|
return '0.0.0';
|
2024-09-24 16:24:31 +02:00
|
|
|
}
|
|
|
|
|
2024-09-11 00:38:21 +02:00
|
|
|
/**
|
|
|
|
* Getter function for the active event plugins.
|
|
|
|
*
|
|
|
|
* @return Event_Plugin[]
|
|
|
|
*/
|
|
|
|
public function get_active_event_plugins() {
|
|
|
|
return $this->active_event_plugins;
|
2024-09-06 14:58:21 +02:00
|
|
|
}
|
|
|
|
|
2024-09-11 00:38:21 +02:00
|
|
|
/**
|
|
|
|
* Holds all the classes for the supported event plugins.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private const EVENT_PLUGIN_CLASSES = array(
|
2024-12-05 16:16:30 +01:00
|
|
|
'\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',
|
2024-09-11 00:38:21 +02:00
|
|
|
);
|
|
|
|
|
2024-12-12 23:24:36 +01:00
|
|
|
/**
|
|
|
|
* Force the re-scan for active event plugins without using the cached transient.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function redetect_active_event_plugins(): void {
|
|
|
|
delete_transient( 'event_bridge_for_activitypub_active_event_plugins' );
|
|
|
|
$this->detect_active_event_plugins();
|
|
|
|
}
|
|
|
|
|
2024-07-05 13:29:13 +02:00
|
|
|
/**
|
|
|
|
* Function that checks for supported activated event plugins.
|
|
|
|
*
|
|
|
|
* @return array List of supported event plugins as keys from the SUPPORTED_EVENT_PLUGINS const.
|
|
|
|
*/
|
2024-12-12 23:24:36 +01:00
|
|
|
public function detect_active_event_plugins(): array {
|
|
|
|
$active_event_plugins = get_transient( 'event_bridge_for_activitypub_active_event_plugins' );
|
2024-09-11 00:38:21 +02:00
|
|
|
|
2024-12-12 23:24:36 +01:00
|
|
|
if ( $active_event_plugins ) {
|
|
|
|
$this->active_event_plugins = $active_event_plugins;
|
|
|
|
return $active_event_plugins;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! function_exists( 'get_plugins' ) ) {
|
|
|
|
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
|
|
|
}
|
|
|
|
|
|
|
|
$all_plugins = array_merge( get_plugins(), get_mu_plugins() );
|
2024-09-11 00:38:21 +02:00
|
|
|
|
2024-12-12 23:24:36 +01:00
|
|
|
$active_event_plugins = array();
|
2024-09-11 00:38:21 +02:00
|
|
|
foreach ( self::EVENT_PLUGIN_CLASSES as $event_plugin_class ) {
|
2024-12-12 23:24:36 +01:00
|
|
|
$event_plugin_file = call_user_func( array( $event_plugin_class, 'get_relative_plugin_file' ) );
|
|
|
|
if ( ! $event_plugin_file ) {
|
2024-09-11 00:38:21 +02:00
|
|
|
continue;
|
|
|
|
}
|
2024-12-12 23:24:36 +01:00
|
|
|
if ( array_key_exists( $event_plugin_file, $all_plugins ) && \is_plugin_active( $event_plugin_file ) ) {
|
|
|
|
$active_event_plugins[ $event_plugin_file ] = new $event_plugin_class();
|
2024-07-05 13:29:13 +02:00
|
|
|
}
|
|
|
|
}
|
2024-12-12 23:24:36 +01:00
|
|
|
set_transient( 'event_bridge_for_activitypub_active_event_plugins', $active_event_plugins );
|
|
|
|
$this->active_event_plugins = $active_event_plugins;
|
2024-07-05 13:29:13 +02:00
|
|
|
return $active_event_plugins;
|
|
|
|
}
|
|
|
|
|
2024-12-09 18:16:07 +01:00
|
|
|
/**
|
|
|
|
* Function that checks which event plugins support the event sources feature.
|
|
|
|
*
|
|
|
|
* @return array List of supported event plugins as keys from the SUPPORTED_EVENT_PLUGINS const.
|
|
|
|
*/
|
|
|
|
public static function detect_event_plugins_supporting_event_sources(): array {
|
|
|
|
$plugins_supporting_event_sources = array();
|
|
|
|
|
|
|
|
foreach ( self::EVENT_PLUGIN_CLASSES as $event_plugin_class ) {
|
|
|
|
if ( ! class_exists( $event_plugin_class ) || ! method_exists( $event_plugin_class, 'get_plugin_file' ) ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ( call_user_func( array( $event_plugin_class, 'supports_event_sources' ) ) ) {
|
|
|
|
$plugins_supporting_event_sources[] = new $event_plugin_class();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $plugins_supporting_event_sources;
|
|
|
|
}
|
|
|
|
|
2024-07-05 13:29:13 +02:00
|
|
|
/**
|
|
|
|
* Set up hooks for various purposes.
|
|
|
|
*
|
|
|
|
* This method adds hooks for different purposes as needed.
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2024-12-12 23:24:36 +01:00
|
|
|
public function setup_hooks(): void {
|
|
|
|
$this->detect_active_event_plugins();
|
|
|
|
|
2024-12-05 16:16:30 +01:00
|
|
|
register_activation_hook( EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_FILE, array( $this, 'activate' ) );
|
2024-07-05 13:29:13 +02:00
|
|
|
|
2024-12-12 23:24:36 +01:00
|
|
|
add_action( 'activated_plugin', array( $this, 'redetect_active_event_plugins' ) );
|
|
|
|
add_action( 'deactivated_plugin', array( $this, 'redetect_active_event_plugins' ) );
|
|
|
|
|
2024-07-05 13:29:13 +02:00
|
|
|
add_action( 'admin_init', array( $this, 'do_admin_notices' ) );
|
2024-08-27 21:23:33 +02:00
|
|
|
add_action( 'admin_init', array( Settings::class, 'register_settings' ) );
|
2024-08-28 17:48:15 +02:00
|
|
|
add_action( 'admin_enqueue_scripts', array( self::class, 'enqueue_styles' ) );
|
2024-08-27 21:23:33 +02:00
|
|
|
add_action( 'admin_menu', array( Settings_Page::class, 'admin_menu' ) );
|
2024-08-15 15:59:58 +02:00
|
|
|
add_filter(
|
2024-12-05 16:16:30 +01:00
|
|
|
'plugin_action_links_' . EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_BASENAME,
|
2024-08-27 21:23:33 +02:00
|
|
|
array( Settings_Page::class, 'settings_link' )
|
2024-08-15 15:59:58 +02:00
|
|
|
);
|
2024-09-11 13:55:37 +02:00
|
|
|
|
2024-10-19 16:46:50 +02:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
add_action( 'init', array( Health_Check::class, 'init' ) );
|
|
|
|
|
2024-09-11 13:55:37 +02:00
|
|
|
// Check if the minimum required version of the ActivityPub plugin is installed.
|
2024-12-05 16:16:30 +01:00
|
|
|
if ( ! version_compare( $this->activitypub_plugin_version, EVENT_BRIDGE_FOR_ACTIVITYPUB_ACTIVITYPUB_PLUGIN_MIN_VERSION ) ) {
|
2024-09-11 13:55:37 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-12-15 13:42:57 +01:00
|
|
|
if ( ! is_user_type_disabled( 'blog' ) && get_option( 'event_bridge_for_activitypub_event_sources_active' ) ) {
|
2024-12-10 19:34:15 +01:00
|
|
|
add_action( 'init', array( Event_Sources_Collection::class, 'init' ) );
|
2024-12-11 23:09:12 +01:00
|
|
|
add_action( 'activitypub_register_handlers', array( Handler::class, 'register_handlers' ) );
|
2024-12-15 09:52:20 +01:00
|
|
|
add_action( 'admin_init', array( User_Interface::class, 'init' ) );
|
2024-12-14 14:46:00 +01:00
|
|
|
add_filter( 'allowed_redirect_hosts', array( Event_Sources_Collection::class, 'add_event_sources_hosts_to_allowed_redirect_hosts' ) );
|
|
|
|
add_filter( 'activitypub_is_post_disabled', array( Event_Sources::class, 'is_cached_external_post' ), 10, 2 );
|
2024-12-15 09:52:20 +01:00
|
|
|
if ( ! wp_next_scheduled( 'event_bridge_for_activitypub_event_sources_clear_cache' ) ) {
|
|
|
|
wp_schedule_event( time(), 'daily', 'event_bridge_for_activitypub_event_sources_clear_cache' );
|
|
|
|
}
|
|
|
|
|
|
|
|
add_action( 'event_bridge_for_activitypub_event_sources_clear_cache', array( Event_Sources::class, 'clear_cache' ) );
|
2024-12-15 13:42:57 +01:00
|
|
|
add_filter( 'activitypub_rest_following', array( Event_Sources::class, 'add_event_sources_to_following_collection' ), 10, 2 );
|
2024-12-15 09:52:20 +01:00
|
|
|
add_filter(
|
|
|
|
'gatherpress_force_online_event_link',
|
|
|
|
function ( $force_online_event_link ) {
|
|
|
|
// Get the current post object.
|
|
|
|
$post = get_post();
|
|
|
|
|
|
|
|
// Check if we are in a valid context and the post type is 'gatherpress'.
|
|
|
|
if ( $post && 'gatherpress_event' === $post->post_type ) {
|
|
|
|
// Add your custom logic here to decide whether to force the link.
|
|
|
|
// For example, force it only if a specific meta field exists.
|
|
|
|
if ( get_post_meta( $post->ID, 'event_bridge_for_activitypub_is_cached', true ) ) {
|
|
|
|
return true; // Force the online event link.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $force_online_event_link; // Default behavior.
|
|
|
|
},
|
|
|
|
10,
|
|
|
|
1
|
|
|
|
);
|
2024-12-10 19:34:15 +01:00
|
|
|
}
|
2024-12-11 23:27:32 +01:00
|
|
|
\add_filter( 'template_include', array( \Event_Bridge_For_ActivityPub\Event_Sources::class, 'redirect_activitypub_requests_for_cached_external_events' ), 100 );
|
2024-07-05 13:29:13 +02:00
|
|
|
add_filter( 'activitypub_transformer', array( $this, 'register_activitypub_event_transformer' ), 10, 3 );
|
|
|
|
}
|
|
|
|
|
2024-08-28 17:48:15 +02:00
|
|
|
/**
|
|
|
|
* Add the CSS for the admin pages.
|
|
|
|
*
|
|
|
|
* @param string $hook_suffix The suffix of the hook.
|
2024-09-11 00:38:21 +02:00
|
|
|
*
|
|
|
|
* @return void
|
2024-08-28 17:48:15 +02:00
|
|
|
*/
|
2024-09-11 00:38:21 +02:00
|
|
|
public static function enqueue_styles( $hook_suffix ): void {
|
2024-12-05 16:16:30 +01:00
|
|
|
if ( false !== strpos( $hook_suffix, 'event-bridge-for-activitypub' ) ) {
|
2024-08-28 17:48:15 +02:00
|
|
|
wp_enqueue_style(
|
2024-12-05 16:16:30 +01:00
|
|
|
'event-bridge-for-activitypub-admin-styles',
|
2024-08-28 17:48:15 +02:00
|
|
|
plugins_url(
|
2024-12-05 16:16:30 +01:00
|
|
|
'assets/css/event-bridge-for-activitypub-admin.css',
|
|
|
|
EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_FILE
|
2024-08-28 17:48:15 +02:00
|
|
|
),
|
|
|
|
array(),
|
2024-12-05 16:16:30 +01:00
|
|
|
EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_VERSION
|
2024-08-28 17:48:15 +02:00
|
|
|
);
|
2024-10-22 18:52:57 +02:00
|
|
|
wp_enqueue_script(
|
2024-12-05 16:16:30 +01:00
|
|
|
'event-bridge-for-activitypub-admin-script',
|
2024-10-22 18:52:57 +02:00
|
|
|
plugins_url(
|
2024-12-05 16:16:30 +01:00
|
|
|
'assets/js/event-bridge-for-activitypub-admin.js',
|
|
|
|
EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_FILE
|
2024-10-22 18:52:57 +02:00
|
|
|
),
|
|
|
|
array( 'jquery' ),
|
2024-12-05 16:16:30 +01:00
|
|
|
EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_VERSION,
|
2024-10-22 18:52:57 +02:00
|
|
|
false
|
|
|
|
);
|
2024-08-28 17:48:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-05 13:29:13 +02:00
|
|
|
/**
|
2024-07-05 15:09:53 +02:00
|
|
|
* Fires the initialization of admin notices.
|
2024-07-05 13:29:13 +02:00
|
|
|
*/
|
|
|
|
public function do_admin_notices(): void {
|
|
|
|
foreach ( $this->active_event_plugins as $event_plugin ) {
|
|
|
|
new Event_Plugin_Admin_Notices( $event_plugin );
|
|
|
|
}
|
2024-07-05 15:09:53 +02:00
|
|
|
// Check if any general admin notices are needed and add actions to insert the needed admin notices.
|
2024-07-05 13:29:13 +02:00
|
|
|
if ( ! $this->activitypub_plugin_is_active ) {
|
2024-07-05 15:09:53 +02:00
|
|
|
// The ActivityPub plugin is not active.
|
2024-12-05 16:16:30 +01:00
|
|
|
add_action( 'admin_notices', array( 'Event_Bridge_For_ActivityPub\Admin\General_Admin_Notices', 'activitypub_plugin_not_enabled' ), 10, 1 );
|
2024-07-05 13:29:13 +02:00
|
|
|
}
|
2024-12-05 16:16:30 +01:00
|
|
|
if ( ! version_compare( $this->activitypub_plugin_version, EVENT_BRIDGE_FOR_ACTIVITYPUB_ACTIVITYPUB_PLUGIN_MIN_VERSION ) ) {
|
2024-09-11 13:55:37 +02:00
|
|
|
// The ActivityPub plugin is too old.
|
2024-12-05 16:16:30 +01:00
|
|
|
add_action( 'admin_notices', array( 'Event_Bridge_For_ActivityPub\Admin\General_Admin_Notices', 'activitypub_plugin_version_too_old' ), 10, 1 );
|
2024-09-11 13:55:37 +02:00
|
|
|
}
|
2024-07-05 13:29:13 +02:00
|
|
|
if ( empty( $this->active_event_plugins ) ) {
|
2024-07-05 15:09:53 +02:00
|
|
|
// No supported Event Plugin is active.
|
2024-12-05 16:16:30 +01:00
|
|
|
add_action( 'admin_notices', array( 'Event_Bridge_For_ActivityPub\Admin\General_Admin_Notices', 'no_supported_event_plugin_active' ), 10, 1 );
|
2024-07-05 13:29:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the custom transformers for the events of several WordPress event plugins.
|
|
|
|
*
|
|
|
|
* @param Activitypub\Transformer\Base $transformer The transformer to use.
|
|
|
|
* @param mixed $wp_object The WordPress object to transform.
|
|
|
|
* @param string $object_class The class of the object to transform.
|
|
|
|
*
|
|
|
|
* @return \Activitypub\Transformer\Base|null
|
|
|
|
*/
|
2024-11-24 10:19:46 +01:00
|
|
|
public function register_activitypub_event_transformer( $transformer, $wp_object, $object_class ): ?\Activitypub\Transformer\Base {
|
2024-07-05 13:29:13 +02:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the transformer for a specific event plugins event-post type.
|
|
|
|
foreach ( $this->active_event_plugins as $event_plugin ) {
|
2024-09-11 00:38:21 +02:00
|
|
|
if ( $wp_object->post_type === $event_plugin->get_post_type() ) {
|
2024-09-24 16:24:31 +02:00
|
|
|
$transformer_class = $event_plugin::get_activitypub_event_transformer_class();
|
2024-09-11 00:38:21 +02:00
|
|
|
if ( class_exists( $transformer_class ) ) {
|
2024-09-24 16:24:31 +02:00
|
|
|
return new $transformer_class( $wp_object, $event_plugin::get_event_category_taxonomy() );
|
2024-09-11 00:38:21 +02:00
|
|
|
}
|
2024-07-05 13:29:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the default transformer.
|
|
|
|
return $transformer;
|
|
|
|
}
|
|
|
|
|
2024-09-10 18:39:26 +02:00
|
|
|
/**
|
|
|
|
* Activates ActivityPub support for all active event plugins event post-types.
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function activate_activitypub_support_for_active_event_plugins(): void {
|
|
|
|
// If someone installs this plugin, we simply enable ActivityPub support for all currently active event post types.
|
|
|
|
$activitypub_supported_post_types = get_option( 'activitypub_support_post_types', array() );
|
|
|
|
foreach ( $this->active_event_plugins as $event_plugin ) {
|
2024-09-24 16:24:31 +02:00
|
|
|
if ( ! in_array( $event_plugin->get_post_type(), $activitypub_supported_post_types, true ) ) {
|
|
|
|
$activitypub_supported_post_types[] = $event_plugin->get_post_type();
|
2024-10-29 21:23:50 +01:00
|
|
|
add_post_type_support( $event_plugin->get_post_type(), 'activitypub' );
|
2024-09-10 18:39:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
update_option( 'activitypub_support_post_types', $activitypub_supported_post_types );
|
|
|
|
}
|
|
|
|
|
2024-07-05 13:29:13 +02:00
|
|
|
/**
|
2024-12-05 16:16:30 +01:00
|
|
|
* Activates the Event Bridge for ActivityPub plugin.
|
2024-07-05 13:29:13 +02:00
|
|
|
*
|
2024-12-05 16:16:30 +01:00
|
|
|
* This method handles the activation of the Event Bridge for ActivityPub plugin.
|
2024-07-05 13:29:13 +02:00
|
|
|
*
|
|
|
|
* @since 1.0.0
|
2024-10-19 16:46:50 +02:00
|
|
|
* @see register_activation_hook()
|
2024-07-05 13:29:13 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
2024-09-11 00:38:21 +02:00
|
|
|
public function activate(): void {
|
2024-12-12 23:24:36 +01:00
|
|
|
$this->redetect_active_event_plugins();
|
2024-07-05 13:29:13 +02:00
|
|
|
// Don't allow plugin activation, when the ActivityPub plugin is not activated yet.
|
|
|
|
if ( ! $this->activitypub_plugin_is_active ) {
|
2024-12-05 16:16:30 +01:00
|
|
|
deactivate_plugins( plugin_basename( EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_FILE ) );
|
2024-07-05 15:09:53 +02:00
|
|
|
$notice = General_Admin_Notices::get_admin_notice_activitypub_plugin_not_enabled();
|
|
|
|
wp_die(
|
|
|
|
wp_kses( $notice, General_Admin_Notices::ALLOWED_HTML ),
|
|
|
|
'Plugin dependency check',
|
|
|
|
array( 'back_link' => true ),
|
2024-07-05 13:29:13 +02:00
|
|
|
);
|
2024-07-05 15:09:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( empty( $this->active_event_plugins ) ) {
|
2024-12-05 16:16:30 +01:00
|
|
|
deactivate_plugins( plugin_basename( EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_FILE ) );
|
2024-07-05 15:09:53 +02:00
|
|
|
$notice = General_Admin_Notices::get_admin_notice_no_supported_event_plugin_active();
|
2024-07-05 13:29:13 +02:00
|
|
|
wp_die(
|
2024-07-05 15:09:53 +02:00
|
|
|
wp_kses( $notice, General_Admin_Notices::ALLOWED_HTML ),
|
2024-07-05 13:29:13 +02:00
|
|
|
'Plugin dependency check',
|
|
|
|
array( 'back_link' => true ),
|
|
|
|
);
|
|
|
|
}
|
2024-09-10 18:39:26 +02:00
|
|
|
|
|
|
|
self::activate_activitypub_support_for_active_event_plugins();
|
2024-07-05 13:29:13 +02:00
|
|
|
}
|
2024-12-10 19:34:15 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the transmogrifier.
|
|
|
|
*/
|
|
|
|
public static function get_transmogrifier() {
|
|
|
|
$setup = self::get_instance();
|
|
|
|
|
|
|
|
$event_sources_active = get_option( 'event_bridge_for_activitypub_event_sources_active', false );
|
|
|
|
$event_plugin = get_option( 'event_bridge_for_activitypub_plugin_used_for_event_source_feature', '' );
|
|
|
|
|
|
|
|
if ( ! $event_sources_active || ! $event_plugin ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$active_event_plugins = $setup->get_active_event_plugins();
|
2024-12-10 22:43:13 +01:00
|
|
|
foreach ( $active_event_plugins as $active_event_plugin ) {
|
|
|
|
if ( strrpos( $active_event_plugin::class, $event_plugin ) ) {
|
|
|
|
return $active_event_plugin::get_transmogrifier_class();
|
|
|
|
}
|
2024-12-10 19:34:15 +01:00
|
|
|
}
|
|
|
|
}
|
2024-07-05 13:29:13 +02:00
|
|
|
}
|