2024-09-11 00:38:21 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Interface for defining supported Event Plugins.
|
|
|
|
*
|
|
|
|
* Basic information that each supported event needs for this plugin to work.
|
|
|
|
*
|
2024-12-05 16:16:30 +01:00
|
|
|
* @package Event_Bridge_For_ActivityPub
|
2024-09-11 00:38:21 +02:00
|
|
|
* @since 1.0.0
|
2024-12-08 21:57:53 +01:00
|
|
|
* @license AGPL-3.0-or-later
|
2024-09-11 00:38:21 +02:00
|
|
|
*/
|
|
|
|
|
2024-12-05 16:16:30 +01:00
|
|
|
namespace Event_Bridge_For_ActivityPub\Integrations;
|
2024-09-11 00:38:21 +02:00
|
|
|
|
2024-12-05 16:16:30 +01:00
|
|
|
use Event_Bridge_For_ActivityPub\Activitypub\Transformer\Event as Event_Transformer;
|
2024-09-11 00:38:21 +02:00
|
|
|
|
|
|
|
// Exit if accessed directly.
|
|
|
|
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interface for a supported event plugin.
|
|
|
|
*
|
|
|
|
* This interface defines which information is necessary for a supported event plugin.
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
*/
|
|
|
|
abstract class Event_Plugin {
|
|
|
|
/**
|
|
|
|
* Returns the full plugin file.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
abstract public static function get_plugin_file(): string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the event post type of the plugin.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
abstract public static function get_post_type(): string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the taxonomy used for the plugin's event categories.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2024-09-18 21:26:53 +02:00
|
|
|
abstract public static function get_event_category_taxonomy(): string;
|
2024-09-11 00:38:21 +02:00
|
|
|
|
|
|
|
/**
|
2024-10-19 16:46:50 +02:00
|
|
|
* Returns the IDs of the admin pages of the plugin.
|
2024-09-11 00:38:21 +02:00
|
|
|
*
|
2024-10-19 16:46:50 +02:00
|
|
|
* @return array The IDs of one or several admin/settings pages.
|
2024-09-11 00:38:21 +02:00
|
|
|
*/
|
2024-10-19 16:46:50 +02:00
|
|
|
public static function get_settings_pages(): array {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2024-12-08 22:36:40 +01:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2024-10-19 16:46:50 +02:00
|
|
|
/**
|
|
|
|
* Get the plugins name from the main plugin-file's top-level-file-comment.
|
|
|
|
*/
|
|
|
|
final public static function get_plugin_name(): string {
|
|
|
|
$plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . static::get_plugin_file() );
|
|
|
|
if ( isset( $plugin_data['Name'] ) ) {
|
|
|
|
return $plugin_data['Name'];
|
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
2024-09-11 00:38:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Detects whether the current screen is a admin page of the event plugin.
|
|
|
|
*/
|
|
|
|
public static function is_plugin_page(): bool {
|
|
|
|
// Get the current page.
|
|
|
|
$screen = get_current_screen();
|
|
|
|
|
|
|
|
// Check if we are on a edit page for the event, or on the settings page of the event plugin.
|
|
|
|
$is_event_plugins_edit_page = 'edit' === $screen->base && static::get_post_type() === $screen->post_type;
|
2024-10-19 16:46:50 +02:00
|
|
|
$is_event_plugins_settings_page = in_array( $screen->id, static::get_settings_pages(), true );
|
2024-09-11 00:38:21 +02:00
|
|
|
|
|
|
|
return $is_event_plugins_edit_page || $is_event_plugins_settings_page;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the Activitypub transformer for the event plugins event post type.
|
|
|
|
*/
|
|
|
|
public static function get_activitypub_event_transformer_class(): string {
|
2024-12-05 16:16:30 +01:00
|
|
|
return str_replace( 'Integrations', 'Activitypub\Transformer', static::class );
|
2024-09-11 00:38:21 +02:00
|
|
|
}
|
2024-12-10 19:34:15 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the class used for transmogrifying an Event (ActivityStreams to Event plugin transformation).
|
|
|
|
*/
|
|
|
|
public static function get_transmogrifier_class(): ?string {
|
2024-12-10 22:43:13 +01:00
|
|
|
if ( ! static::supports_event_sources() ) {
|
2024-12-10 19:34:15 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return str_replace( 'Integrations', 'Activitypub\Transmogrifier', static::class );
|
|
|
|
}
|
2024-09-11 00:38:21 +02:00
|
|
|
}
|