2024-09-11 00:38:21 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2024-12-16 17:36:23 +01:00
|
|
|
* Abstract base class for a basic integration of a WordPress event plugin.
|
2024-09-11 00:38:21 +02:00
|
|
|
*
|
2024-12-16 17:36:23 +01:00
|
|
|
* Basic information and methods that each supported event needs for this plugin to work.
|
2024-09-11 00:38:21 +02:00
|
|
|
*
|
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-16 17:36:23 +01:00
|
|
|
use Event_Bridge_For_ActivityPub\ActivityPub\Transformer\Event as ActivityPub_Event_Transformer;
|
2024-09-11 00:38:21 +02:00
|
|
|
|
|
|
|
// Exit if accessed directly.
|
|
|
|
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
|
|
|
|
2024-12-15 22:25:28 +01:00
|
|
|
require_once EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_DIR . 'includes/integrations/interface-feature-event-sources.php';
|
|
|
|
|
2024-09-11 00:38:21 +02:00
|
|
|
/**
|
2024-12-16 17:36:23 +01:00
|
|
|
* Abstract base class for a basic integration of a WordPress event plugin.
|
2024-09-11 00:38:21 +02:00
|
|
|
*
|
2024-12-16 17:36:23 +01:00
|
|
|
* Basic information and methods that each supported event needs for this plugin to work.
|
2024-09-11 00:38:21 +02:00
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
*/
|
2024-12-15 22:25:28 +01:00
|
|
|
abstract class Event_Plugin_Integration {
|
2024-09-11 00:38:21 +02:00
|
|
|
/**
|
2024-12-12 23:24:36 +01:00
|
|
|
* Returns the plugin file relative to the plugins dir.
|
2024-09-11 00:38:21 +02:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2024-12-12 23:24:36 +01:00
|
|
|
abstract public static function get_relative_plugin_file(): string;
|
2024-09-11 00:38:21 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-12-15 22:25:28 +01:00
|
|
|
* Returns the Activitypub transformer for the event plugins event post type.
|
2024-09-11 00:38:21 +02:00
|
|
|
*
|
2024-12-15 22:25:28 +01:00
|
|
|
* @param WP_Post $post The WordPress post object of the Event.
|
|
|
|
* @return ActivityPub_Event_Transformer
|
2024-09-11 00:38:21 +02:00
|
|
|
*/
|
2024-12-15 22:25:28 +01:00
|
|
|
abstract public static function get_activitypub_event_transformer( $post ): ActivityPub_Event_Transformer;
|
2024-10-19 16:46:50 +02:00
|
|
|
|
2024-12-22 21:55:08 +01:00
|
|
|
/**
|
|
|
|
* In case an event plugin used a custom post type for the locations/venues return it here.
|
|
|
|
*
|
|
|
|
* @return ?string
|
|
|
|
*/
|
|
|
|
public static function get_location_post_type() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2024-12-08 22:36:40 +01:00
|
|
|
/**
|
2024-12-15 22:25:28 +01:00
|
|
|
* Returns the IDs of the admin pages of the plugin.
|
2024-12-08 22:36:40 +01:00
|
|
|
*
|
2024-12-15 22:25:28 +01:00
|
|
|
* @return array The IDs of one or several admin/settings pages.
|
2024-12-08 22:36:40 +01:00
|
|
|
*/
|
2024-12-15 22:25:28 +01:00
|
|
|
public static function get_settings_pages(): array {
|
|
|
|
return array();
|
2024-12-08 22:36:40 +01:00
|
|
|
}
|
|
|
|
|
2024-10-19 16:46:50 +02:00
|
|
|
/**
|
|
|
|
* Get the plugins name from the main plugin-file's top-level-file-comment.
|
|
|
|
*/
|
2024-12-15 22:25:28 +01:00
|
|
|
public static function get_plugin_name(): string {
|
2024-12-12 23:24:36 +01:00
|
|
|
$all_plugins = array_merge( get_plugins(), get_mu_plugins() );
|
|
|
|
if ( isset( $all_plugins[ static::get_relative_plugin_file() ]['Name'] ) ) {
|
|
|
|
return $all_plugins[ static::get_relative_plugin_file() ]['Name'];
|
2024-10-19 16:46:50 +02:00
|
|
|
} 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;
|
|
|
|
}
|
|
|
|
}
|