diff --git a/activitypub-event-extensions.php b/activitypub-event-extensions.php
index 65424df..42f8b48 100644
--- a/activitypub-event-extensions.php
+++ b/activitypub-event-extensions.php
@@ -1,15 +1,17 @@
tribe_event = \tribe_get_event( $wp_object );
}
diff --git a/includes/activitypub/transformer/class-vs-event-list.php b/includes/activitypub/transformer/class-vs-event-list.php
index 8eb6af3..a91e5f1 100644
--- a/includes/activitypub/transformer/class-vs-event-list.php
+++ b/includes/activitypub/transformer/class-vs-event-list.php
@@ -26,7 +26,7 @@ if ( ! defined( 'ABSPATH' ) ) {
*
* @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.
@@ -44,7 +44,7 @@ class VS_Event_List extends Event_Transformer {
* @access public
* @return string Widget name.
*/
- public function get_transformer_name() {
+ public function get_transformer_name(): string {
return 'activitypub-event-transformers/vs-event';
}
@@ -57,7 +57,7 @@ class VS_Event_List extends Event_Transformer {
* @access public
* @return string Widget title.
*/
- public function get_transformer_label() {
+ public function get_transformer_label(): string {
return 'VS Event';
}
@@ -70,7 +70,7 @@ class VS_Event_List extends Event_Transformer {
* @access public
* @return array Widget categories.
*/
- public static function get_supported_post_types() {
+ public static function get_supported_post_types(): string {
return array( 'event' );
}
@@ -81,16 +81,16 @@ class VS_Event_List extends Event_Transformer {
* @since 1.0.0
* @return string The Event Object-Type.
*/
- protected function get_type() {
+ protected function get_type(): string {
return 'Event';
}
/**
* 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 );
$place = new Place();
$place->set_type( 'Place' );
@@ -102,7 +102,7 @@ class VS_Event_List extends Event_Transformer {
/**
* 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 );
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.
*/
- protected function get_start_time() {
+ protected function get_start_time(): string {
$start_time = get_post_meta( $this->wp_object->ID, 'event-start-date', true );
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.
*/
- private function get_event_link() {
+ private function get_event_link(): array {
$event_link = get_post_meta( $this->wp_object->ID, 'event-link', true );
if ( $event_link ) {
return array(
diff --git a/includes/admin/class-event-plugin-admin-notices.php b/includes/admin/class-event-plugin-admin-notices.php
index 82e8670..9340e81 100644
--- a/includes/admin/class-event-plugin-admin-notices.php
+++ b/includes/admin/class-event-plugin-admin-notices.php
@@ -11,6 +11,8 @@
namespace Activitypub_Event_Extensions\Admin;
+use Activitypub_Event_Extensions\Plugins\Event_Plugin;
+
/**
* Class responsible for Event Plugin related admin notices.
*
@@ -22,14 +24,14 @@ class Event_Plugin_Admin_Notices {
/**
* Information about the event plugin.
*
- * @var array
+ * @var Event_Plugin
*/
protected $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 ) {
$this->event_plugin = $event_plugin;
@@ -43,32 +45,28 @@ class Event_Plugin_Admin_Notices {
*
* @return bool
*/
- private function event_post_type_is_not_activitypub_enabled() {
- return ! in_array( $this->event_plugin['post_type'], get_option( 'activitypub_support_post_types', array() ), true );
+ private function event_post_type_is_not_activitypub_enabled(): bool {
+ return ! in_array( $this->event_plugin::get_post_type(), get_option( 'activitypub_support_post_types', array() ), true );
}
/**
* Display the admin notices for the plugins.
+ *
+ * @return void
*/
- public function admin_notice_activitypub_not_enabled_for_post_type() {
- // 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 && $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'] );
+ public function admin_notice_activitypub_not_enabled_for_post_type(): void {
+ if ( $this->event_plugin::is_plugin_page() ) {
+ $this->do_admin_notice_post_type_not_activitypub_enabled();
}
}
/**
* 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 ) {
- $event_plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $event_plugin_file );
+ private function do_admin_notice_post_type_not_activitypub_enabled(): void {
+ $event_plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $this->event_plugin::get_plugin_file() );
$activitypub_plugin_data = get_plugin_data( ACTIVITYPUB_PLUGIN_FILE );
$notice = sprintf(
/* translators: 1: the name of the event plugin a admin notice is shown. 2: The name of the ActivityPub plugin. */
diff --git a/includes/admin/class-general-admin-notices.php b/includes/admin/class-general-admin-notices.php
index 8c69512..a4de156 100644
--- a/includes/admin/class-general-admin-notices.php
+++ b/includes/admin/class-general-admin-notices.php
@@ -84,7 +84,7 @@ class General_Admin_Notices {
*
* @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();
echo '
' . \wp_kses( $notice, self::ALLOWED_HTML ) . '
';
}
@@ -94,7 +94,7 @@ class General_Admin_Notices {
*
* @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();
echo '' . \wp_kses( $notice, self::ALLOWED_HTML ) . '
';
}
diff --git a/includes/admin/class-settings-page.php b/includes/admin/class-settings-page.php
index 22c8b1a..2a3b569 100644
--- a/includes/admin/class-settings-page.php
+++ b/includes/admin/class-settings-page.php
@@ -12,6 +12,7 @@
namespace Activitypub_Event_Extensions\Admin;
use Activitypub_Event_Extensions\Setup;
+use Activitypub_Event_Extensions\Plugins\Event_Plugin;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
@@ -59,19 +60,20 @@ class Settings_Page {
/**
* 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.
*/
private static function get_event_terms( $event_plugin ) {
- if ( isset( $event_plugin['taxonomy'] ) ) {
+ $taxonomy = $event_plugin::get_taxonomy();
+ if ( $taxonomy ) {
$event_terms = get_terms(
array(
- 'taxonomy' => $event_plugin['taxonomy'],
+ 'taxonomy' => $taxonomy,
'hide_empty' => true,
)
);
- return $event_terms;
+ return ! is_wp_error( $event_terms ) ? $event_terms : array();
} else {
return array();
}
@@ -87,8 +89,8 @@ class Settings_Page {
$event_terms = array();
- foreach ( $event_plugins as $event_plugin_name => $events_plugin_info ) {
- $event_terms = array_merge( $event_terms, self::get_event_terms( $events_plugin_info ) );
+ foreach ( $event_plugins as $event_plugin ) {
+ $event_terms = array_merge( $event_terms, self::get_event_terms( $event_plugin ) );
}
$args = array(
diff --git a/includes/class-settings.php b/includes/class-settings.php
index 26248af..ceec701 100644
--- a/includes/class-settings.php
+++ b/includes/class-settings.php
@@ -26,12 +26,19 @@ defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
class Settings {
const SETTINGS_SLUG = 'activitypub-event-extensions';
+ /**
+ * The default ActivityPub event category.
+ *
+ * @var string
+ */
const DEFAULT_EVENT_CATEGORY = 'MEETING';
/**
* Register the settings for the ActivityPub Event Extensions plugin.
+ *
+ * @return void
*/
- public static function register_settings() {
+ public static function register_settings(): void {
\register_setting(
'activitypub-event-extensions',
'activitypub_event_extensions_default_event_category',
@@ -61,7 +68,7 @@ class Settings {
*
* @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;
}
@@ -71,8 +78,10 @@ class Settings {
* Currently only the default event categories are allowed to be target of a mapping.
*
* @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 ) ) {
return array();
}
@@ -91,7 +100,7 @@ class Settings {
*
* @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;
return in_array( $event_category, $allowed_event_categories, true );
}
diff --git a/includes/class-setup.php b/includes/class-setup.php
index 47552b8..e075ee0 100644
--- a/includes/class-setup.php
+++ b/includes/class-setup.php
@@ -15,6 +15,7 @@ namespace Activitypub_Event_Extensions;
use Activitypub_Event_Extensions\Admin\Event_Plugin_Admin_Notices;
use Activitypub_Event_Extensions\Admin\General_Admin_Notices;
use Activitypub_Event_Extensions\Admin\Settings_Page;
+use Activitypub_Event_Extensions\Plugins\Event_Plugin;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
@@ -29,34 +30,6 @@ require_once ABSPATH . 'wp-admin/includes/plugin.php';
* @since 1.0.0
*/
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.
*
@@ -67,7 +40,7 @@ class Setup {
/**
* Holds an array of the currently activated supported event plugins.
*
- * @var array
+ * @var Event_Plugin[]
*/
protected $active_event_plugins = array();
@@ -80,7 +53,7 @@ class Setup {
*/
protected function __construct() {
$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();
}
@@ -109,28 +82,46 @@ class Setup {
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.
+ *
+ * @return Event_Plugin[]
*/
public function get_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.
@@ -167,8 +158,10 @@ class Setup {
* Add the CSS for the admin pages.
*
* @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' ) ) {
wp_enqueue_style(
'activitypub-event-extensions-admin-styles',
@@ -218,9 +211,11 @@ class Setup {
// Get the transformer for a specific event plugins event-post type.
foreach ( $this->active_event_plugins as $event_plugin ) {
- if ( $wp_object->post_type === $event_plugin['post_type'] ) {
- $transformer_class = 'Activitypub_Event_Extensions\Activitypub\Transformer\\' . $event_plugin['transformer_class'];
- return new $transformer_class( $wp_object, $event_plugin['taxonomy'] );
+ if ( $wp_object->post_type === $event_plugin->get_post_type() ) {
+ $transformer_class = $event_plugin->get_activitypub_event_transformer_class();
+ if ( class_exists( $transformer_class ) ) {
+ return new $transformer_class( $wp_object, $event_plugin->get_taxonomy() );
+ }
}
}
@@ -255,7 +250,7 @@ class Setup {
*
* @return void
*/
- public function activate() {
+ public function activate(): void {
// Don't allow plugin activation, when the ActivityPub plugin is not activated yet.
if ( ! $this->activitypub_plugin_is_active ) {
deactivate_plugins( plugin_basename( ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_FILE ) );
diff --git a/includes/plugins/class-event-plugin.php b/includes/plugins/class-event-plugin.php
new file mode 100644
index 0000000..25b753b
--- /dev/null
+++ b/includes/plugins/class-event-plugin.php
@@ -0,0 +1,76 @@
+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 );
+ }
+}
diff --git a/includes/plugins/class-events-manager.php b/includes/plugins/class-events-manager.php
new file mode 100644
index 0000000..26a8926
--- /dev/null
+++ b/includes/plugins/class-events-manager.php
@@ -0,0 +1,60 @@
+
-
+