Merge pull request 'Refactoring: each event plugin is now represented by the implementation of a Event_Plugin base class.' (#24) from class_plugin_adapter into main
Reviewed-on: Event-Federation/wordpress-activitypub-event-extensions#24
This commit is contained in:
commit
126327288f
16 changed files with 448 additions and 103 deletions
|
@ -8,8 +8,10 @@
|
||||||
* Author URI: https://graz.social/@linos
|
* Author URI: https://graz.social/@linos
|
||||||
* Text Domain: activitypub-event-extensions
|
* Text Domain: activitypub-event-extensions
|
||||||
* License: AGPL-3.0-or-later
|
* License: AGPL-3.0-or-later
|
||||||
|
* License URI: https://www.gnu.org/licenses/agpl-3.0.de.html
|
||||||
|
* Requires PHP: 8.1
|
||||||
*
|
*
|
||||||
* ActivityPub tested up to: 3.1.0
|
* ActivityPub plugin tested up to: 3.2.2
|
||||||
*
|
*
|
||||||
* @package activitypub-event-extensions
|
* @package activitypub-event-extensions
|
||||||
* @license AGPL-3.0-or-later
|
* @license AGPL-3.0-or-later
|
||||||
|
|
|
@ -23,7 +23,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
class Events_Manager extends Event_Transformer {
|
final class Events_Manager extends Event_Transformer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the EM_Event object.
|
* Holds the EM_Event object.
|
||||||
|
|
|
@ -23,7 +23,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
class GatherPress extends Event {
|
final class GatherPress extends Event {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The target ActivityPub Event object of the transformer.
|
* The target ActivityPub Event object of the transformer.
|
||||||
|
|
|
@ -22,7 +22,7 @@ use WP_Post;
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
class The_Events_Calendar extends Event {
|
final class The_Events_Calendar extends Event {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Tribe Event object.
|
* The Tribe Event object.
|
||||||
|
@ -38,9 +38,10 @@ class The_Events_Calendar extends Event {
|
||||||
* has a lot of useful functions, we make use of our getter functions.
|
* has a lot of useful functions, we make use of our getter functions.
|
||||||
*
|
*
|
||||||
* @param WP_Post $wp_object The WordPress object.
|
* @param WP_Post $wp_object The WordPress object.
|
||||||
|
* @param string $wp_taxonomy The taxonomy slug of the event post type.
|
||||||
*/
|
*/
|
||||||
public function __construct( $wp_object ) {
|
public function __construct( $wp_object, $wp_taxonomy ) {
|
||||||
parent::__construct( $wp_object );
|
parent::__construct( $wp_object, $wp_taxonomy );
|
||||||
$this->tribe_event = \tribe_get_event( $wp_object );
|
$this->tribe_event = \tribe_get_event( $wp_object );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
class VS_Event_List extends Event_Transformer {
|
final class VS_Event_List extends Event_Transformer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The target transformer ActivityPub Event object.
|
* The target transformer ActivityPub Event object.
|
||||||
|
@ -44,7 +44,7 @@ class VS_Event_List extends Event_Transformer {
|
||||||
* @access public
|
* @access public
|
||||||
* @return string Widget name.
|
* @return string Widget name.
|
||||||
*/
|
*/
|
||||||
public function get_transformer_name() {
|
public function get_transformer_name(): string {
|
||||||
return 'activitypub-event-transformers/vs-event';
|
return 'activitypub-event-transformers/vs-event';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ class VS_Event_List extends Event_Transformer {
|
||||||
* @access public
|
* @access public
|
||||||
* @return string Widget title.
|
* @return string Widget title.
|
||||||
*/
|
*/
|
||||||
public function get_transformer_label() {
|
public function get_transformer_label(): string {
|
||||||
return 'VS Event';
|
return 'VS Event';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ class VS_Event_List extends Event_Transformer {
|
||||||
* @access public
|
* @access public
|
||||||
* @return array Widget categories.
|
* @return array Widget categories.
|
||||||
*/
|
*/
|
||||||
public static function get_supported_post_types() {
|
public static function get_supported_post_types(): string {
|
||||||
return array( 'event' );
|
return array( 'event' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,16 +81,16 @@ class VS_Event_List extends Event_Transformer {
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @return string The Event Object-Type.
|
* @return string The Event Object-Type.
|
||||||
*/
|
*/
|
||||||
protected function get_type() {
|
protected function get_type(): string {
|
||||||
return 'Event';
|
return 'Event';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the event location.
|
* Get the event location.
|
||||||
*
|
*
|
||||||
* @return array The Place.
|
* @return Place The Place.
|
||||||
*/
|
*/
|
||||||
public function get_location() {
|
public function get_location(): Place {
|
||||||
$address = get_post_meta( $this->wp_object->ID, 'event-location', true );
|
$address = get_post_meta( $this->wp_object->ID, 'event-location', true );
|
||||||
$place = new Place();
|
$place = new Place();
|
||||||
$place->set_type( 'Place' );
|
$place->set_type( 'Place' );
|
||||||
|
@ -102,7 +102,7 @@ class VS_Event_List extends Event_Transformer {
|
||||||
/**
|
/**
|
||||||
* Get the end time from the events metadata.
|
* Get the end time from the events metadata.
|
||||||
*/
|
*/
|
||||||
protected function get_end_time() {
|
protected function get_end_time(): string {
|
||||||
$end_time = get_post_meta( $this->wp_object->ID, 'event-date', true );
|
$end_time = get_post_meta( $this->wp_object->ID, 'event-date', true );
|
||||||
return \gmdate( 'Y-m-d\TH:i:s\Z', $end_time );
|
return \gmdate( 'Y-m-d\TH:i:s\Z', $end_time );
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ class VS_Event_List extends Event_Transformer {
|
||||||
/**
|
/**
|
||||||
* Get the end time from the events metadata.
|
* Get the end time from the events metadata.
|
||||||
*/
|
*/
|
||||||
protected function get_start_time() {
|
protected function get_start_time(): string {
|
||||||
$start_time = get_post_meta( $this->wp_object->ID, 'event-start-date', true );
|
$start_time = get_post_meta( $this->wp_object->ID, 'event-start-date', true );
|
||||||
return \gmdate( 'Y-m-d\TH:i:s\Z', $start_time );
|
return \gmdate( 'Y-m-d\TH:i:s\Z', $start_time );
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ class VS_Event_List extends Event_Transformer {
|
||||||
/**
|
/**
|
||||||
* Get the event link from the events metadata.
|
* Get the event link from the events metadata.
|
||||||
*/
|
*/
|
||||||
private function get_event_link() {
|
private function get_event_link(): array {
|
||||||
$event_link = get_post_meta( $this->wp_object->ID, 'event-link', true );
|
$event_link = get_post_meta( $this->wp_object->ID, 'event-link', true );
|
||||||
if ( $event_link ) {
|
if ( $event_link ) {
|
||||||
return array(
|
return array(
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
|
|
||||||
namespace Activitypub_Event_Extensions\Admin;
|
namespace Activitypub_Event_Extensions\Admin;
|
||||||
|
|
||||||
|
use Activitypub_Event_Extensions\Plugins\Event_Plugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class responsible for Event Plugin related admin notices.
|
* Class responsible for Event Plugin related admin notices.
|
||||||
*
|
*
|
||||||
|
@ -22,14 +24,14 @@ class Event_Plugin_Admin_Notices {
|
||||||
/**
|
/**
|
||||||
* Information about the event plugin.
|
* Information about the event plugin.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var Event_Plugin
|
||||||
*/
|
*/
|
||||||
protected $event_plugin;
|
protected $event_plugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds admin notices to an active supported event plugin.
|
* Adds admin notices to an active supported event plugin.
|
||||||
*
|
*
|
||||||
* @param array $event_plugin Information about the activate event plugin.
|
* @param Event_Plugin $event_plugin Class that has implements functions to handle a certain supported activate event plugin.
|
||||||
*/
|
*/
|
||||||
public function __construct( $event_plugin ) {
|
public function __construct( $event_plugin ) {
|
||||||
$this->event_plugin = $event_plugin;
|
$this->event_plugin = $event_plugin;
|
||||||
|
@ -43,32 +45,28 @@ class Event_Plugin_Admin_Notices {
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function event_post_type_is_not_activitypub_enabled() {
|
private function event_post_type_is_not_activitypub_enabled(): bool {
|
||||||
return ! in_array( $this->event_plugin['post_type'], get_option( 'activitypub_support_post_types', array() ), true );
|
return ! in_array( $this->event_plugin::get_post_type(), get_option( 'activitypub_support_post_types', array() ), true );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display the admin notices for the plugins.
|
* Display the admin notices for the plugins.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function admin_notice_activitypub_not_enabled_for_post_type() {
|
public function admin_notice_activitypub_not_enabled_for_post_type(): void {
|
||||||
// Get the current page.
|
if ( $this->event_plugin::is_plugin_page() ) {
|
||||||
$screen = get_current_screen();
|
$this->do_admin_notice_post_type_not_activitypub_enabled();
|
||||||
// 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 && $this->event_plugin['post_type'] === $screen->post_type;
|
|
||||||
$is_event_plugins_settings_page = $this->event_plugin['settings_page_id'] === $screen->id;
|
|
||||||
|
|
||||||
if ( $is_event_plugins_edit_page || $is_event_plugins_settings_page ) {
|
|
||||||
$this->do_admin_notice_post_type_not_activitypub_enabled( $this->event_plugin['plugin_file'] );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print admin notice that the current post type is not enabled in the ActivityPub plugin.
|
* Print admin notice that the current post type is not enabled in the ActivityPub plugin.
|
||||||
*
|
*
|
||||||
* @param string $event_plugin_file The event plugin file path.
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function do_admin_notice_post_type_not_activitypub_enabled( $event_plugin_file ) {
|
private function do_admin_notice_post_type_not_activitypub_enabled(): void {
|
||||||
$event_plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $event_plugin_file );
|
$event_plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $this->event_plugin::get_plugin_file() );
|
||||||
$activitypub_plugin_data = get_plugin_data( ACTIVITYPUB_PLUGIN_FILE );
|
$activitypub_plugin_data = get_plugin_data( ACTIVITYPUB_PLUGIN_FILE );
|
||||||
$notice = sprintf(
|
$notice = sprintf(
|
||||||
/* translators: 1: the name of the event plugin a admin notice is shown. 2: The name of the ActivityPub plugin. */
|
/* translators: 1: the name of the event plugin a admin notice is shown. 2: The name of the ActivityPub plugin. */
|
||||||
|
|
|
@ -84,7 +84,7 @@ class General_Admin_Notices {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function activitypub_plugin_not_enabled() {
|
public static function activitypub_plugin_not_enabled(): void {
|
||||||
$notice = self::get_admin_notice_activitypub_plugin_not_enabled();
|
$notice = self::get_admin_notice_activitypub_plugin_not_enabled();
|
||||||
echo '<div class="notice notice-warning"><p>' . \wp_kses( $notice, self::ALLOWED_HTML ) . '</p></div>';
|
echo '<div class="notice notice-warning"><p>' . \wp_kses( $notice, self::ALLOWED_HTML ) . '</p></div>';
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ class General_Admin_Notices {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function no_supported_event_plugin_active() {
|
public static function no_supported_event_plugin_active(): void {
|
||||||
$notice = self::get_admin_notice_no_supported_event_plugin_active();
|
$notice = self::get_admin_notice_no_supported_event_plugin_active();
|
||||||
echo '<div class="notice notice-warning"><p>' . \wp_kses( $notice, self::ALLOWED_HTML ) . '</p></div>';
|
echo '<div class="notice notice-warning"><p>' . \wp_kses( $notice, self::ALLOWED_HTML ) . '</p></div>';
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
namespace Activitypub_Event_Extensions\Admin;
|
namespace Activitypub_Event_Extensions\Admin;
|
||||||
|
|
||||||
use Activitypub_Event_Extensions\Setup;
|
use Activitypub_Event_Extensions\Setup;
|
||||||
|
use Activitypub_Event_Extensions\Plugins\Event_Plugin;
|
||||||
|
|
||||||
// Exit if accessed directly.
|
// Exit if accessed directly.
|
||||||
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||||
|
@ -59,19 +60,20 @@ class Settings_Page {
|
||||||
/**
|
/**
|
||||||
* Receive the event categories (terms) used by the event plugin.
|
* Receive the event categories (terms) used by the event plugin.
|
||||||
*
|
*
|
||||||
* @param array $event_plugin Contains info about a certain event plugin.
|
* @param Event_Plugin $event_plugin Contains info about a certain event plugin.
|
||||||
*
|
*
|
||||||
* @return array An array of Terms.
|
* @return array An array of Terms.
|
||||||
*/
|
*/
|
||||||
private static function get_event_terms( $event_plugin ) {
|
private static function get_event_terms( $event_plugin ) {
|
||||||
if ( isset( $event_plugin['taxonomy'] ) ) {
|
$taxonomy = $event_plugin::get_taxonomy();
|
||||||
|
if ( $taxonomy ) {
|
||||||
$event_terms = get_terms(
|
$event_terms = get_terms(
|
||||||
array(
|
array(
|
||||||
'taxonomy' => $event_plugin['taxonomy'],
|
'taxonomy' => $taxonomy,
|
||||||
'hide_empty' => true,
|
'hide_empty' => true,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
return $event_terms;
|
return ! is_wp_error( $event_terms ) ? $event_terms : array();
|
||||||
} else {
|
} else {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
@ -87,8 +89,8 @@ class Settings_Page {
|
||||||
|
|
||||||
$event_terms = array();
|
$event_terms = array();
|
||||||
|
|
||||||
foreach ( $event_plugins as $event_plugin_name => $events_plugin_info ) {
|
foreach ( $event_plugins as $event_plugin ) {
|
||||||
$event_terms = array_merge( $event_terms, self::get_event_terms( $events_plugin_info ) );
|
$event_terms = array_merge( $event_terms, self::get_event_terms( $event_plugin ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
$args = array(
|
$args = array(
|
||||||
|
|
|
@ -26,12 +26,19 @@ defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||||
class Settings {
|
class Settings {
|
||||||
const SETTINGS_SLUG = 'activitypub-event-extensions';
|
const SETTINGS_SLUG = 'activitypub-event-extensions';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default ActivityPub event category.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
const DEFAULT_EVENT_CATEGORY = 'MEETING';
|
const DEFAULT_EVENT_CATEGORY = 'MEETING';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the settings for the ActivityPub Event Extensions plugin.
|
* Register the settings for the ActivityPub Event Extensions plugin.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function register_settings() {
|
public static function register_settings(): void {
|
||||||
\register_setting(
|
\register_setting(
|
||||||
'activitypub-event-extensions',
|
'activitypub-event-extensions',
|
||||||
'activitypub_event_extensions_default_event_category',
|
'activitypub_event_extensions_default_event_category',
|
||||||
|
@ -61,7 +68,7 @@ class Settings {
|
||||||
*
|
*
|
||||||
* @param string $event_category The ActivityPUb event category.
|
* @param string $event_category The ActivityPUb event category.
|
||||||
*/
|
*/
|
||||||
public static function sanitize_mapped_event_category( $event_category ) {
|
public static function sanitize_mapped_event_category( $event_category ): string {
|
||||||
return self::is_allowed_event_category( $event_category ) ? $event_category : self::DEFAULT_EVENT_CATEGORY;
|
return self::is_allowed_event_category( $event_category ) ? $event_category : self::DEFAULT_EVENT_CATEGORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,8 +78,10 @@ class Settings {
|
||||||
* Currently only the default event categories are allowed to be target of a mapping.
|
* Currently only the default event categories are allowed to be target of a mapping.
|
||||||
*
|
*
|
||||||
* @param array $event_category_mappings The settings value.
|
* @param array $event_category_mappings The settings value.
|
||||||
|
*
|
||||||
|
* @return array An array that contains only valid mapping pairs.
|
||||||
*/
|
*/
|
||||||
public static function sanitize_event_category_mappings( $event_category_mappings ) {
|
public static function sanitize_event_category_mappings( $event_category_mappings ): array {
|
||||||
if ( empty( $event_category_mappings ) ) {
|
if ( empty( $event_category_mappings ) ) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
@ -91,7 +100,7 @@ class Settings {
|
||||||
*
|
*
|
||||||
* @return bool True if allowed, false otherwise.
|
* @return bool True if allowed, false otherwise.
|
||||||
*/
|
*/
|
||||||
private static function is_allowed_event_category( $event_category ) {
|
private static function is_allowed_event_category( $event_category ): bool {
|
||||||
$allowed_event_categories = Event::DEFAULT_EVENT_CATEGORIES;
|
$allowed_event_categories = Event::DEFAULT_EVENT_CATEGORIES;
|
||||||
return in_array( $event_category, $allowed_event_categories, true );
|
return in_array( $event_category, $allowed_event_categories, true );
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ namespace Activitypub_Event_Extensions;
|
||||||
use Activitypub_Event_Extensions\Admin\Event_Plugin_Admin_Notices;
|
use Activitypub_Event_Extensions\Admin\Event_Plugin_Admin_Notices;
|
||||||
use Activitypub_Event_Extensions\Admin\General_Admin_Notices;
|
use Activitypub_Event_Extensions\Admin\General_Admin_Notices;
|
||||||
use Activitypub_Event_Extensions\Admin\Settings_Page;
|
use Activitypub_Event_Extensions\Admin\Settings_Page;
|
||||||
|
use Activitypub_Event_Extensions\Plugins\Event_Plugin;
|
||||||
|
|
||||||
// Exit if accessed directly.
|
// Exit if accessed directly.
|
||||||
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||||
|
@ -29,34 +30,6 @@ require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
class Setup {
|
class Setup {
|
||||||
const SUPPORTED_EVENT_PLUGINS = array(
|
|
||||||
'events_manager' => array(
|
|
||||||
'plugin_file' => 'events-manager/events-manager.php',
|
|
||||||
'post_type' => 'event',
|
|
||||||
'settings_page' => 'options-general.php?page=vsel',
|
|
||||||
'transformer_class' => 'Events_Manager',
|
|
||||||
),
|
|
||||||
'gatherpress' => array(
|
|
||||||
'plugin_file' => 'gatherpress/gatherpress.php',
|
|
||||||
'post_type' => 'gatherpress_event',
|
|
||||||
'transformer_class' => 'GatherPress',
|
|
||||||
'settings_page_id' => 'gatherpress_general',
|
|
||||||
),
|
|
||||||
'the_events_calendar' => array(
|
|
||||||
'plugin_file' => 'the-events-calendar/the-events-calendar.php',
|
|
||||||
'post_type' => 'tribe_events',
|
|
||||||
'transformer_class' => 'Tribe',
|
|
||||||
'settings_page_id' => 'tribe_general',
|
|
||||||
),
|
|
||||||
'vsel' => array(
|
|
||||||
'plugin_file' => 'very-simple-event-list/vsel.php',
|
|
||||||
'post_type' => 'event',
|
|
||||||
'settings_page_id' => 'settings_page_vsel',
|
|
||||||
'transformer_class' => 'VS_Event_List',
|
|
||||||
'taxonomy' => 'event_cat',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keep the information whether the ActivityPub plugin is active.
|
* Keep the information whether the ActivityPub plugin is active.
|
||||||
*
|
*
|
||||||
|
@ -67,7 +40,7 @@ class Setup {
|
||||||
/**
|
/**
|
||||||
* Holds an array of the currently activated supported event plugins.
|
* Holds an array of the currently activated supported event plugins.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var Event_Plugin[]
|
||||||
*/
|
*/
|
||||||
protected $active_event_plugins = array();
|
protected $active_event_plugins = array();
|
||||||
|
|
||||||
|
@ -80,7 +53,7 @@ class Setup {
|
||||||
*/
|
*/
|
||||||
protected function __construct() {
|
protected function __construct() {
|
||||||
$this->activitypub_plugin_is_active = is_plugin_active( 'activitypub/activitypub.php' );
|
$this->activitypub_plugin_is_active = is_plugin_active( 'activitypub/activitypub.php' );
|
||||||
$this->active_event_plugins = self::detect_supported_event_plugins();
|
$this->active_event_plugins = self::detect_active_event_plugins();
|
||||||
$this->setup_hooks();
|
$this->setup_hooks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,28 +82,46 @@ class Setup {
|
||||||
return self::$instance;
|
return self::$instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Function that checks for supported activated event plugins.
|
|
||||||
*
|
|
||||||
* @return array List of supported event plugins as keys from the SUPPORTED_EVENT_PLUGINS const.
|
|
||||||
*/
|
|
||||||
public static function detect_supported_event_plugins(): array {
|
|
||||||
$active_event_plugins = array();
|
|
||||||
foreach ( self::SUPPORTED_EVENT_PLUGINS as $event_plugin_key => $event_plugin ) {
|
|
||||||
if ( \is_plugin_active( $event_plugin['plugin_file'] ) ) {
|
|
||||||
$active_event_plugins[ $event_plugin_key ] = $event_plugin;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $active_event_plugins;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter function for the active event plugins.
|
* Getter function for the active event plugins.
|
||||||
|
*
|
||||||
|
* @return Event_Plugin[]
|
||||||
*/
|
*/
|
||||||
public function get_active_event_plugins() {
|
public function get_active_event_plugins() {
|
||||||
return $this->active_event_plugins;
|
return $this->active_event_plugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds all the classes for the supported event plugins.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private const EVENT_PLUGIN_CLASSES = array(
|
||||||
|
'\Activitypub_Event_Extensions\Plugins\Events_Manager',
|
||||||
|
'\Activitypub_Event_Extensions\Plugins\GatherPress',
|
||||||
|
'\Activitypub_Event_Extensions\Plugins\The_Events_Calendar',
|
||||||
|
'\Activitypub_Event_Extensions\Plugins\VS_Event_List',
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function that checks for supported activated event plugins.
|
||||||
|
*
|
||||||
|
* @return array List of supported event plugins as keys from the SUPPORTED_EVENT_PLUGINS const.
|
||||||
|
*/
|
||||||
|
public static function detect_active_event_plugins(): array {
|
||||||
|
$active_event_plugins = 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;
|
||||||
|
}
|
||||||
|
$event_plugin_file = call_user_func( array( $event_plugin_class, 'get_plugin_file' ) );
|
||||||
|
if ( \is_plugin_active( $event_plugin_file ) ) {
|
||||||
|
$active_event_plugins[] = new $event_plugin_class();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $active_event_plugins;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up hooks for various purposes.
|
* Set up hooks for various purposes.
|
||||||
|
@ -167,8 +158,10 @@ class Setup {
|
||||||
* Add the CSS for the admin pages.
|
* Add the CSS for the admin pages.
|
||||||
*
|
*
|
||||||
* @param string $hook_suffix The suffix of the hook.
|
* @param string $hook_suffix The suffix of the hook.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function enqueue_styles( $hook_suffix ) {
|
public static function enqueue_styles( $hook_suffix ): void {
|
||||||
if ( false !== strpos( $hook_suffix, 'activitypub-event-extensions' ) ) {
|
if ( false !== strpos( $hook_suffix, 'activitypub-event-extensions' ) ) {
|
||||||
wp_enqueue_style(
|
wp_enqueue_style(
|
||||||
'activitypub-event-extensions-admin-styles',
|
'activitypub-event-extensions-admin-styles',
|
||||||
|
@ -218,9 +211,11 @@ class Setup {
|
||||||
|
|
||||||
// Get the transformer for a specific event plugins event-post type.
|
// Get the transformer for a specific event plugins event-post type.
|
||||||
foreach ( $this->active_event_plugins as $event_plugin ) {
|
foreach ( $this->active_event_plugins as $event_plugin ) {
|
||||||
if ( $wp_object->post_type === $event_plugin['post_type'] ) {
|
if ( $wp_object->post_type === $event_plugin->get_post_type() ) {
|
||||||
$transformer_class = 'Activitypub_Event_Extensions\Activitypub\Transformer\\' . $event_plugin['transformer_class'];
|
$transformer_class = $event_plugin->get_activitypub_event_transformer_class();
|
||||||
return new $transformer_class( $wp_object, $event_plugin['taxonomy'] );
|
if ( class_exists( $transformer_class ) ) {
|
||||||
|
return new $transformer_class( $wp_object, $event_plugin->get_taxonomy() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,7 +250,7 @@ class Setup {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function activate() {
|
public function activate(): void {
|
||||||
// Don't allow plugin activation, when the ActivityPub plugin is not activated yet.
|
// Don't allow plugin activation, when the ActivityPub plugin is not activated yet.
|
||||||
if ( ! $this->activitypub_plugin_is_active ) {
|
if ( ! $this->activitypub_plugin_is_active ) {
|
||||||
deactivate_plugins( plugin_basename( ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_FILE ) );
|
deactivate_plugins( plugin_basename( ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_FILE ) );
|
||||||
|
|
76
includes/plugins/class-event-plugin.php
Normal file
76
includes/plugins/class-event-plugin.php
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Interface for defining supported Event Plugins.
|
||||||
|
*
|
||||||
|
* Basic information that each supported event needs for this plugin to work.
|
||||||
|
*
|
||||||
|
* @package Activitypub_Event_Extensions
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Activitypub_Event_Extensions\Plugins;
|
||||||
|
|
||||||
|
use Activitypub_Event_Extensions\Activitypub\Transformer\Event as Event_Transformer;
|
||||||
|
|
||||||
|
// 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
|
||||||
|
*/
|
||||||
|
abstract public static function get_taxonomy(): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ID of the main settings page of the plugin.
|
||||||
|
*
|
||||||
|
* @return string The settings page url.
|
||||||
|
*/
|
||||||
|
public static function get_settings_page(): string {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
$is_event_plugins_settings_page = static::get_settings_page() === $screen->id;
|
||||||
|
|
||||||
|
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 {
|
||||||
|
return str_replace( 'Plugins', 'Activitypub\Transformer', static::class );
|
||||||
|
}
|
||||||
|
}
|
60
includes/plugins/class-events-manager.php
Normal file
60
includes/plugins/class-events-manager.php
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Events Manager.
|
||||||
|
*
|
||||||
|
* Defines all the necessary meta information for the Events Manager WordPress Plugin.
|
||||||
|
*
|
||||||
|
* @link https://wordpress.org/plugins/events-manager/
|
||||||
|
* @package Activitypub_Event_Extensions
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Activitypub_Event_Extensions\Plugins;
|
||||||
|
|
||||||
|
// 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
|
||||||
|
*/
|
||||||
|
final class Events_Manager extends Event_Plugin {
|
||||||
|
/**
|
||||||
|
* Returns the full plugin file.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_plugin_file(): string {
|
||||||
|
return 'events-manager/events-manager.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the event post type of the plugin.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_post_type(): string {
|
||||||
|
return defined( 'EM_POST_TYPE_EVENT' ) ? constant( 'EM_POST_TYPE_EVENT' ) : 'event';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ID of the main settings page of the plugin.
|
||||||
|
*
|
||||||
|
* @return string The settings page url.
|
||||||
|
*/
|
||||||
|
public static function get_settings_page(): string {
|
||||||
|
return 'wp-admin/edit.php?post_type=event&page=events-manager-options#general';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the taxonomy used for the plugin's event categories.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_taxonomy(): string {
|
||||||
|
return defined( 'EM_TAXONOMY_CATEGORY' ) ? constant( 'EM_TAXONOMY_CATEGORY' ) : 'event-categories';
|
||||||
|
}
|
||||||
|
}
|
69
includes/plugins/class-gatherpress.php
Normal file
69
includes/plugins/class-gatherpress.php
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* GatherPress.
|
||||||
|
*
|
||||||
|
* Defines all the necessary meta information for the GatherPress plugin.
|
||||||
|
*
|
||||||
|
* @link https://wordpress.org/plugins/gatherpress/
|
||||||
|
* @package Activitypub_Event_Extensions
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Activitypub_Event_Extensions\Plugins;
|
||||||
|
|
||||||
|
// 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
|
||||||
|
*/
|
||||||
|
final class GatherPress extends Event_Plugin {
|
||||||
|
/**
|
||||||
|
* Returns the full plugin file.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_plugin_file(): string {
|
||||||
|
return 'gatherpress/gatherpress.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the event post type of the plugin.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_post_type(): string {
|
||||||
|
return class_exists( '\GatherPress\Core\Event' ) ? \GatherPress\Core\Event::POST_TYPE : 'gatherpress_event';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ID of the main settings page of the plugin.
|
||||||
|
*
|
||||||
|
* @return string The settings page url.
|
||||||
|
*/
|
||||||
|
public static function get_settings_page(): string {
|
||||||
|
return class_exists( '\GatherPress\Core\Utility' ) ? \GatherPress\Core\Utility::prefix_key( 'general' ) : 'gatherpress_general';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ActivityPub transformer class.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_activitypub_transformer_class_name(): string {
|
||||||
|
return 'GatherPress';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the taxonomy used for the plugin's event categories.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_taxonomy(): string {
|
||||||
|
return class_exists( '\GatherPress\Core\Topic' ) ? \GatherPress\Core\Topic::TAXONOMY : 'gatherpress_topic';
|
||||||
|
}
|
||||||
|
}
|
61
includes/plugins/class-the-events-calendar.php
Normal file
61
includes/plugins/class-the-events-calendar.php
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* The Events Calendar.
|
||||||
|
*
|
||||||
|
* Defines all the necessary meta information for the events calendar.
|
||||||
|
*
|
||||||
|
* @link https://wordpress.org/plugins/the-events-calendar/
|
||||||
|
* @package Activitypub_Event_Extensions
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Activitypub_Event_Extensions\Plugins;
|
||||||
|
|
||||||
|
// 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
|
||||||
|
*/
|
||||||
|
final class The_Events_Calendar extends Event_plugin {
|
||||||
|
/**
|
||||||
|
* Returns the full plugin file.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_plugin_file(): string {
|
||||||
|
return 'the-events-calendar/the-events-calendar.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the event post type of the plugin.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_post_type(): string {
|
||||||
|
return class_exists( '\Tribe__Events__Main' ) ? \Tribe__Events__Main::POSTTYPE : 'tribe_event';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ID of the main settings page of the plugin.
|
||||||
|
*
|
||||||
|
* @return string The settings page url.
|
||||||
|
*/
|
||||||
|
public static function get_settings_page(): string {
|
||||||
|
// TODO: Tribe\Events\Admin\Settings::settings_page_id.
|
||||||
|
return 'edit.php?post_type=tribe_events&page=tec-events-settings';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the taxonomy used for the plugin's event categories.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_taxonomy(): string {
|
||||||
|
return class_exists( '\Tribe__Events__Main' ) ? \Tribe__Events__Main::TAXONOMY : 'tribe_events_cat';
|
||||||
|
}
|
||||||
|
}
|
72
includes/plugins/class-vs-event-list.php
Normal file
72
includes/plugins/class-vs-event-list.php
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* VS Events LIst.
|
||||||
|
*
|
||||||
|
* Defines all the necessary meta information for the WordPress event plugin
|
||||||
|
* "Very Simple Events List".
|
||||||
|
*
|
||||||
|
* @link https://de.wordpress.org/plugins/very-simple-event-list/
|
||||||
|
* @package Activitypub_Event_Extensions
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Activitypub_Event_Extensions\Plugins;
|
||||||
|
|
||||||
|
use Activitypub_Event_Extensions\Event_Plugins;
|
||||||
|
|
||||||
|
// 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
|
||||||
|
*/
|
||||||
|
final class VS_Event_List extends Event_Plugin {
|
||||||
|
/**
|
||||||
|
* Returns the full plugin file.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_plugin_file(): string {
|
||||||
|
return 'very-simple-event-list/vsel.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the event post type of the plugin.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_post_type(): string {
|
||||||
|
return 'event';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ID of the main settings page of the plugin.
|
||||||
|
*
|
||||||
|
* @return string The settings page url.
|
||||||
|
*/
|
||||||
|
public static function get_settings_page(): string {
|
||||||
|
return 'settings_page_vsel';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ActivityPub transformer class.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_activitypub_transformer_class_name(): string {
|
||||||
|
return 'VS_Event';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the taxonomy used for the plugin's event categories.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_taxonomy(): string {
|
||||||
|
return 'event_cat';
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue