mindmap on category mapping and class-based event-plugin definition
This commit is contained in:
parent
1f93f58760
commit
771a95aa0c
16 changed files with 713 additions and 168 deletions
|
@ -16,8 +16,19 @@ use function Activitypub\get_rest_url_by_path;
|
|||
|
||||
/**
|
||||
* Base transformer for WordPress event post types to ActivityPub events.
|
||||
*
|
||||
* Everything that transforming several WordPress post types that represent events
|
||||
* have in common, as well as sane defaults for events should be defined here.
|
||||
*/
|
||||
class Event extends Post {
|
||||
|
||||
/**
|
||||
* The WordPress event taxonomy.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $wp_taxonomy;
|
||||
|
||||
/**
|
||||
* Returns the User-URL of the Author of the Post.
|
||||
*
|
||||
|
@ -41,6 +52,19 @@ class Event extends Post {
|
|||
return 'Event';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the event category, via the mapping setting.
|
||||
*/
|
||||
public function get_category() {
|
||||
$current_category_mapping = \get_option( 'activitypub_event_extensions_event_category_mappings', array() );
|
||||
$terms = \get_the_terms( $this->wp_object, $this->wp_taxonomy );
|
||||
if ( ! is_wp_error( $terms ) && $terms ) {
|
||||
return $current_category_mapping[ $terms[0]->slug ];
|
||||
} else {
|
||||
return \get_option( 'activitypub_event_extensions_default_event_category', 'MEETING' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic function that converts an WP-Event object to an ActivityPub-Event object.
|
||||
*
|
||||
|
|
|
@ -6,8 +6,14 @@
|
|||
* @license AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
use Activitypub\Transformer\Post;
|
||||
use Activitypub\Model\Blog_user;
|
||||
namespace Activitypub_Event_Extensions\Activitypub\Transformer;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
use Activitypub_Event_Extensions\Activitypub\Transformer\Event;
|
||||
use Activitypub\Model\Blog;
|
||||
use Activitypub\Activity\Extended_Object\Event as Event_Object;
|
||||
use Activitypub\Activity\Extended_Object\Place;
|
||||
use GatherPress\Core\Event as GatherPress_Event;
|
||||
|
@ -23,7 +29,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class GatherPress extends Post {
|
||||
class GatherPress extends Event {
|
||||
|
||||
/**
|
||||
* The target ActivityPub Event object of the transformer.
|
||||
|
@ -84,7 +90,6 @@ class GatherPress extends Post {
|
|||
* @return array Widget categories.
|
||||
*/
|
||||
public static function get_supported_post_types() {
|
||||
|
||||
return array( GatherPress_Event::POST_TYPE );
|
||||
}
|
||||
|
||||
|
@ -96,7 +101,6 @@ class GatherPress extends Post {
|
|||
* @return string The Event Object-Type.
|
||||
*/
|
||||
protected function get_type() {
|
||||
|
||||
return 'Event';
|
||||
}
|
||||
|
||||
|
@ -119,7 +123,6 @@ class GatherPress extends Post {
|
|||
* Get the end time from the event object.
|
||||
*/
|
||||
protected function get_end_time() {
|
||||
|
||||
return $this->gp_event->get_datetime_end( 'Y-m-d\TH:i:s\Z' );
|
||||
}
|
||||
|
||||
|
@ -127,7 +130,6 @@ class GatherPress extends Post {
|
|||
* Get the end time from the event object.
|
||||
*/
|
||||
protected function get_start_time() {
|
||||
|
||||
return $this->gp_event->get_datetime_start( 'Y-m-d\TH:i:s\Z' );
|
||||
}
|
||||
|
||||
|
@ -135,7 +137,6 @@ class GatherPress extends Post {
|
|||
* Get the event link from the events metadata.
|
||||
*/
|
||||
private function get_event_link() {
|
||||
|
||||
$event_link = get_post_meta( $this->wp_object->ID, 'event-link', true );
|
||||
if ( $event_link ) {
|
||||
return array(
|
||||
|
@ -151,7 +152,6 @@ class GatherPress extends Post {
|
|||
* Overrides/extends the get_attachments function to also add the event Link.
|
||||
*/
|
||||
protected function get_attachment() {
|
||||
|
||||
$attachments = parent::get_attachment();
|
||||
if ( count( $attachments ) ) {
|
||||
$attachments[0]['type'] = 'Document';
|
||||
|
@ -170,7 +170,6 @@ class GatherPress extends Post {
|
|||
* @return string $category
|
||||
*/
|
||||
protected function get_category() {
|
||||
|
||||
return 'MEETING';
|
||||
}
|
||||
|
||||
|
@ -182,8 +181,7 @@ class GatherPress extends Post {
|
|||
* @return string The User-URL.
|
||||
*/
|
||||
protected function get_attributed_to() {
|
||||
|
||||
$user = new Blog_User();
|
||||
$user = new Blog();
|
||||
return $user->get_url();
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
namespace Activitypub_Event_Extensions\Activitypub\Transformer;
|
||||
|
||||
use Activitypub_Event_Extensions\Activitypub\Transformer\Event as Event_Transformer;
|
||||
use Activitypub\Model\Blog;
|
||||
use Activitypub\Activity\Extended_Object\Event;
|
||||
use Activitypub\Activity\Extended_Object\Place;
|
||||
|
||||
|
@ -25,7 +24,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class VS_Event extends Event_Transformer {
|
||||
class VSEL extends Event_Transformer {
|
||||
|
||||
/**
|
||||
* The target transformet ActivityPub Event object.
|
||||
|
@ -205,7 +204,7 @@ class VS_Event extends Event_Transformer {
|
|||
$setter_function = 'set_' . $key;
|
||||
$getter_function = 'get_' . $key;
|
||||
|
||||
if ( in_array( $getter_function, get_class_methods( $this ) ) ) {
|
||||
if ( in_array( $getter_function, get_class_methods( $this ), true ) ) {
|
||||
$this->ap_object->$setter_function( $this->$getter_function() );
|
||||
} else {
|
||||
$this->ap_object->$setter_function( $value );
|
||||
|
@ -220,7 +219,7 @@ class VS_Event extends Event_Transformer {
|
|||
* @param string $method The method name.
|
||||
* @param string $params The method params.
|
||||
*
|
||||
* @return void
|
||||
* @return function
|
||||
*/
|
||||
public function __call( $method, $params ) {
|
||||
|
||||
|
@ -230,8 +229,6 @@ class VS_Event extends Event_Transformer {
|
|||
return $this->set( $var, $params[0] );
|
||||
}
|
||||
|
||||
// when do we need: call_user_func( array( $activitypub_object, $setter ), $value );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,43 +11,29 @@
|
|||
|
||||
namespace Activitypub_Event_Extensions\Admin;
|
||||
|
||||
use Activitypub_Event_Extensions\Setup;
|
||||
|
||||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||
|
||||
/**
|
||||
* Class responsible for Event Plugin related admin notices.
|
||||
* Class responsible for the ActivityPui Event Extension related Settings.
|
||||
*
|
||||
* Notices for guiding to proper configuration of ActivityPub with event plugins.
|
||||
* Class responsible for the ActivityPui Event Extension related Settings.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Settings_Page {
|
||||
|
||||
/**
|
||||
* TODO:
|
||||
* - [ ] create settings page
|
||||
* - [ ] skeleton
|
||||
* - [ ] Autoloader
|
||||
* - [ ] Common settings?
|
||||
* - [ ] Hook points
|
||||
* - [ ] let transformers hook settings into the page
|
||||
* - [ ] provide setting-type-classes for hooks
|
||||
* - [ ] True/False
|
||||
* - [ ] Number
|
||||
* - [ ] advanced for mapping
|
||||
*/
|
||||
|
||||
const STATIC = 'Activitypub_Event_Extensions\Admin\Settings_Page';
|
||||
|
||||
const SETTINGS_SLUG = 'activitypub-events';
|
||||
|
||||
const SETTINGS_SLUG = 'activitypub-event-extensions';
|
||||
/**
|
||||
* Warning if the plugin is Active and the ActivityPub plugin is not.
|
||||
*/
|
||||
public static function admin_menu() {
|
||||
\add_options_page(
|
||||
'Activitypub Event Extension',
|
||||
'Activitypub Events',
|
||||
__( 'ActivityPub Events', 'activitypub_event_extensions' ),
|
||||
'manage_options',
|
||||
self::SETTINGS_SLUG,
|
||||
array( self::STATIC, 'settings_page' )
|
||||
|
@ -70,59 +56,46 @@ class Settings_Page {
|
|||
);
|
||||
}
|
||||
|
||||
public static function settings_page() {
|
||||
if ( empty( $_GET['tab'] ) ) {
|
||||
$tab = 'general';
|
||||
/**
|
||||
* Receive the event categories (terms) used by the event plugin.
|
||||
*
|
||||
* @param array $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'] ) ) {
|
||||
$event_terms = get_terms(
|
||||
array(
|
||||
'taxonomy' => $event_plugin['taxonomy'],
|
||||
'hide_empty' => true,
|
||||
)
|
||||
);
|
||||
return $event_terms;
|
||||
} else {
|
||||
$tab = sanitize_key( $_GET['tab'] );
|
||||
}
|
||||
|
||||
/*
|
||||
submenu_options = {
|
||||
tab => {name => ''
|
||||
active => true|false}
|
||||
}
|
||||
*/
|
||||
|
||||
// TODO: generate this somehow.
|
||||
// Maybe with filters, similar as with the settings!
|
||||
$submenu_options = array(
|
||||
'general' => array(
|
||||
'name' => 'General',
|
||||
'active' => false,
|
||||
),
|
||||
'events_manager' => array(
|
||||
'name' => 'Events Manager',
|
||||
'active' => false,
|
||||
),
|
||||
'gatherpress' => array(
|
||||
'name' => 'Gatherpress',
|
||||
'active' => false,
|
||||
),
|
||||
'the_events_calendar' => array(
|
||||
'name' => 'The Events Calendar',
|
||||
'active' => false,
|
||||
),
|
||||
'vsel' => array(
|
||||
'name' => 'VS Event',
|
||||
'active' => false,
|
||||
),
|
||||
);
|
||||
|
||||
$submenu_options[ $tab ]['active'] = true;
|
||||
|
||||
$args = array(
|
||||
'slug' => self::SETTINGS_SLUG,
|
||||
'options' => $submenu_options,
|
||||
);
|
||||
|
||||
switch ( $tab ) {
|
||||
case 'general':
|
||||
\load_template( ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_DIR . 'templates/settings-general.php', true, $args );
|
||||
break;
|
||||
default:
|
||||
\load_template( ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_DIR . 'templates/settings-extractor.php', true, $args );
|
||||
break;
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings page.
|
||||
*/
|
||||
public static function settings_page() {
|
||||
$plugin_setup = Setup::get_instance();
|
||||
|
||||
$event_plugins = $plugin_setup->get_active_event_plugins();
|
||||
|
||||
$event_terms = array();
|
||||
|
||||
foreach ( $event_plugins as $event_plugin_name => $events_plugin_info ) {
|
||||
$event_terms[ $event_plugin_name ] = self::get_event_terms( $events_plugin_info );
|
||||
}
|
||||
|
||||
$args = array(
|
||||
'slug' => self::SETTINGS_SLUG,
|
||||
'event_terms' => $event_terms,
|
||||
);
|
||||
|
||||
\load_template( ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_DIR . 'templates/settings.php', true, $args );
|
||||
}
|
||||
}
|
||||
|
|
65
includes/admin/class-settings.php
Normal file
65
includes/admin/class-settings.php
Normal file
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
/**
|
||||
* General settings class.
|
||||
*
|
||||
* This file contains the General class definition, which handles the "General" settings
|
||||
* page for the ActivityPub Event Extension Plugin, providing options for configuring various general settings.
|
||||
*
|
||||
* @package Activitypub_Event_Extensions
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
namespace Activitypub_Event_Extensions\Admin;
|
||||
|
||||
use Activitypub\Activity\Extended_Object\Event;
|
||||
|
||||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||
|
||||
/**
|
||||
* Class responsible for the ActivityPui Event Extension related Settings.
|
||||
*
|
||||
* Class responsible for the ActivityPui Event Extension related Settings.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Settings {
|
||||
const STATIC = 'Activitypub_Event_Extensions\Admin\Settings_Page';
|
||||
|
||||
const SETTINGS_SLUG = 'activitypub-event-extensions';
|
||||
|
||||
/**
|
||||
* Register the settings for the ActivityPub Event Extensions plugin.
|
||||
*/
|
||||
public static function register_settings() {
|
||||
\register_setting(
|
||||
'activitypub-event-extensions',
|
||||
'activitypub_event_extensions_default_event_category',
|
||||
array(
|
||||
'type' => 'string',
|
||||
'description' => \__( 'Define your own custom post template', 'activitypub' ),
|
||||
'show_in_rest' => true,
|
||||
'default' => 'MEETING',
|
||||
)
|
||||
);
|
||||
|
||||
\register_setting(
|
||||
'activitypub-event-extensions',
|
||||
'activitypub_event_extensions_event_category_mappings',
|
||||
array(
|
||||
'type' => 'array',
|
||||
'description' => \__( 'Define your own custom post template', 'activitypub' ),
|
||||
'default' => array(),
|
||||
'sanitize_callback' => function ( $event_category_mappings ) {
|
||||
$allowed_mappings = Event::DEFAULT_EVENT_CATEGORIES;
|
||||
foreach ( $event_category_mappings as $key => $value ) {
|
||||
if ( ! in_array( $value, $allowed_mappings, true ) ) {
|
||||
unset( $event_category_mappings[ $key ] );
|
||||
}
|
||||
}
|
||||
return $event_category_mappings;
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
56
includes/class-plugin-manager.php
Normal file
56
includes/class-plugin-manager.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
/**
|
||||
* Class responsible for initializing ActivityPub Event Extensions.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @package Activitypub_Event_Extensions
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
namespace Activitypub_Event_Extensions;
|
||||
|
||||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
|
||||
/**
|
||||
* Class Setup.
|
||||
*
|
||||
* This class is responsible for initializing ActivityPub Event Extensions.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Plugin_Manager {
|
||||
/**
|
||||
* Gets all active supported event plugins.
|
||||
*/
|
||||
public function get_active_event_plugins() {
|
||||
$active_event_plugins = array();
|
||||
|
||||
foreach ( get_declared_classes() as $class ) {
|
||||
if (strpos($class, __NAMESPACE__) === 0) {
|
||||
$reflection = new ReflectionClass($class);
|
||||
|
||||
// Skip interfaces or abstract classes.
|
||||
if ($reflection->isAbstract() || $reflection->isInterface()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($reflection->hasMethod('get_plugin_file')) {
|
||||
$instance = $reflection->newInstance();
|
||||
$plugin_file = $instance->get_plugin_file();
|
||||
|
||||
if (is_plugin_active($plugin_file)) {
|
||||
$active_event_plugins[$class] = $plugin_file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now you can use $active_event_plugins for further processing
|
||||
return $active_event_plugins;
|
||||
}
|
||||
}
|
|
@ -13,7 +13,9 @@ 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;
|
||||
use Activitypub_Event_Extensions\Admin\Settings_Page;
|
||||
use Activitypub_Event_Extensions\Plugins\Gatherpress;
|
||||
|
||||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||
|
@ -29,30 +31,10 @@ require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
|||
*/
|
||||
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',
|
||||
),
|
||||
'Events_Manager',
|
||||
'GatherPress',
|
||||
'The_Events_Calendar',
|
||||
'VS_Event_List',
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -69,6 +51,13 @@ class Setup {
|
|||
*/
|
||||
protected $active_event_plugins = array();
|
||||
|
||||
/**
|
||||
* Getter function for the active event plugins.
|
||||
*/
|
||||
public function get_active_event_plugins() {
|
||||
return $this->active_event_plugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for the Setup class.
|
||||
*
|
||||
|
@ -114,9 +103,10 @@ class Setup {
|
|||
*/
|
||||
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;
|
||||
foreach ( self::SUPPORTED_EVENT_PLUGINS as $event_plugin ) {
|
||||
$event_plugin_class = 'Activitypub_Event_Extensions\Plugins\\' . $event_plugin;
|
||||
if ( \is_plugin_active( $event_plugin_class::get_plugin_file() ) ) {
|
||||
$active_event_plugins[ $event_plugin ] = $event_plugin_class;
|
||||
}
|
||||
}
|
||||
return $active_event_plugins;
|
||||
|
@ -135,17 +125,18 @@ class Setup {
|
|||
register_activation_hook( ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_FILE, array( $this, 'activate' ) );
|
||||
|
||||
add_action( 'admin_init', array( $this, 'do_admin_notices' ) );
|
||||
add_action( 'admin_init', array( Settings::class, 'register_settings' ) );
|
||||
|
||||
// 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( 'admin_menu', array( Settings_Page::STATIC, 'admin_menu' ) );
|
||||
add_action( 'admin_menu', array( Settings_Page::class, 'admin_menu' ) );
|
||||
|
||||
add_filter(
|
||||
'plugin_action_links_' . ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_BASENAME,
|
||||
array( Settings_Page::STATIC, 'settings_link' )
|
||||
array( Settings_Page::class, 'settings_link' )
|
||||
);
|
||||
add_filter( 'activitypub_transformer', array( $this, 'register_activitypub_event_transformer' ), 10, 3 );
|
||||
}
|
||||
|
@ -186,7 +177,7 @@ 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'] ) {
|
||||
if ( $wp_object->post_type === $event_plugin::get_post_type() ) {
|
||||
$transformer_class = 'Activitypub_Event_Extensions\Activitypub\Transformer\\' . $event_plugin['transformer_class'];
|
||||
return new $transformer_class( $wp_object );
|
||||
}
|
||||
|
@ -226,10 +217,11 @@ class Setup {
|
|||
array( 'back_link' => true ),
|
||||
);
|
||||
}
|
||||
|
||||
// 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 ) {
|
||||
if ( ! in_array( $event_plugin['post_type'], $activitypub_supported_post_types, true ) ) {
|
||||
if ( ! in_array( $event_plugin::get_post_type, $activitypub_supported_post_types, true ) ) {
|
||||
$activitypub_supported_post_types[] = $event_plugin['post_type'];
|
||||
}
|
||||
}
|
||||
|
|
71
includes/plugins/class-events-manager.php
Normal file
71
includes/plugins/class-events-manager.php
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?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
|
||||
|
||||
require_once __DIR__ . '/interface-event-plugin.php';
|
||||
|
||||
/**
|
||||
* Interface for a supported event plugin.
|
||||
*
|
||||
* This interface defines which information is necessary for a supported event plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Events_Manager implements 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 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 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 defined( 'EM_TAXONOMY_CATEGORY' ) ? constant( 'EM_TAXONOMY_CATEGORY' ) : 'event-categories';
|
||||
}
|
||||
}
|
76
includes/plugins/class-gatherpress.php
Normal file
76
includes/plugins/class-gatherpress.php
Normal file
|
@ -0,0 +1,76 @@
|
|||
<?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
|
||||
|
||||
require_once __DIR__ . '/interface-event-plugin.php';
|
||||
|
||||
use Activitypub_Event_Extensions\Plugins\Event_Plugin;
|
||||
use GatherPress\Core\Event;
|
||||
use GatherPress\Core\Topic;
|
||||
use GatherPress\Core\Utility;
|
||||
|
||||
/**
|
||||
* Interface for a supported event plugin.
|
||||
*
|
||||
* This interface defines which information is necessary for a supported event plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Gatherpress implements 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 Event::POST_TYPE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 Utility::prefix_key( '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 Topic::TAXONOMY;
|
||||
}
|
||||
}
|
76
includes/plugins/class-the-events-calendar.php
Normal file
76
includes/plugins/class-the-events-calendar.php
Normal file
|
@ -0,0 +1,76 @@
|
|||
<?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
|
||||
|
||||
require_once __DIR__ . '/interface-event-plugin.php';
|
||||
|
||||
use Activitypub_Event_Extensions\Plugins\Event_Plugin;
|
||||
|
||||
/**
|
||||
* Interface for a supported event plugin.
|
||||
*
|
||||
* This interface defines which information is necessary for a supported event plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class The_Events_Calendar implements 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 \Tribe__Events__Main::POSTTYPE;
|
||||
}
|
||||
|
||||
const POST_TYPE = 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 ActivityPub transformer class.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_activitypub_transformer_class_name(): string {
|
||||
return 'Tribe';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the taxonomy used for the plugin's event categories.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_taxonomy(): string {
|
||||
return Tribe__Events__Main::TAXONOMY;
|
||||
}
|
||||
}
|
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;
|
||||
|
||||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||
|
||||
require_once __DIR__ . '/interface-event-plugin.php';
|
||||
|
||||
/**
|
||||
* Interface for a supported event plugin.
|
||||
*
|
||||
* This interface defines which information is necessary for a supported event plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class VS_Event_List implements 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';
|
||||
}
|
||||
}
|
58
includes/plugins/interface-event-plugin.php
Normal file
58
includes/plugins/interface-event-plugin.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?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;
|
||||
|
||||
// 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
|
||||
*/
|
||||
interface Event_Plugin {
|
||||
/**
|
||||
* Returns the full plugin file.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_plugin_file(): string;
|
||||
|
||||
/**
|
||||
* Returns the event post type of the plugin.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_post_type(): 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;
|
||||
|
||||
/**
|
||||
* Returns the ActivityPub transformer class.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_activitypub_transformer_class_name(): string;
|
||||
|
||||
/**
|
||||
* Returns the taxonomy used for the plugin's event categories.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_taxonomy(): string;
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
<!-- TODO css classes?
|
||||
currently reusing activitypub classes which is kinda nice, because it has a consistent theme then, but also it cloud break if activitypub changes something
|
||||
-->
|
||||
<div class="activitypub-settings-header">
|
||||
<div class="activitypub-settings-title-section">
|
||||
<h1><?php \esc_html_e( 'Activitypub Events Plugin', $args['slug'] ); ?></h1>
|
||||
</div>
|
||||
|
||||
<nav class="activitypub-settings-tabs-wrapper" aria-label="<?php \esc_attr_e( 'Secondary menu', $args['slug'] ); ?>">
|
||||
<!-- todo loop through settings pages of Extractors -->
|
||||
<?php foreach ( $args['options'] as $tabslug => $plugin ) { ?>
|
||||
<a href="<?php echo \esc_url_raw( admin_url( 'options-general.php?page='. $args['slug'] .'&tab=' . $tabslug ) ); ?>" class="activitypub-settings-tab <?php echo \esc_attr( $plugin['active'] ? 'active' : '' ); ?>">
|
||||
<?php \esc_html_e( $plugin['name'], $args['slug'] ); ?> <!-- Todo better name handling -->
|
||||
</a>
|
||||
<?php } ?>
|
||||
|
||||
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
<hr class="wp-header-end">
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
// Is this check necessary? it's already enforced by admin_menu()
|
||||
// it's "recommended" by https://developer.wordpress.org/plugins/administration-menus/sub-menus/
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
\load_template(
|
||||
__DIR__ . '/admin-header.php',
|
||||
true,
|
||||
$args
|
||||
);
|
||||
?>
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
// Is this check necessary? it's already enforced by admin_menu()
|
||||
// it's "recommended" by https://developer.wordpress.org/plugins/administration-menus/sub-menus/
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
\load_template(
|
||||
__DIR__ . '/admin-header.php',
|
||||
true,
|
||||
$args
|
||||
);
|
||||
?>
|
134
templates/settings.php
Normal file
134
templates/settings.php
Normal file
|
@ -0,0 +1,134 @@
|
|||
<?php
|
||||
/**
|
||||
* Template for ActivityPub Event Extensions settings pages.
|
||||
*
|
||||
* This template is used to display and manage settings for the ActivityPub Event Extensions plugin.
|
||||
*
|
||||
* @package ActivityPub_Event_Extensions
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $args An array of arguments for the settings page.
|
||||
*/
|
||||
|
||||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||
|
||||
use Activitypub\Activity\Extended_Object\Event;
|
||||
|
||||
if ( ! isset( $args ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event_terms = get_terms(
|
||||
array(
|
||||
'taxonomy' => 'tribe_events_cat',
|
||||
'hide_empty' => true,
|
||||
)
|
||||
);
|
||||
|
||||
$default_event_category_strings = array(
|
||||
'ARTS' => __( 'Arts', 'activitypub-event-extensions' ),
|
||||
'BOOK_CLUBS' => __( 'Book clubs', 'activitypub-event-extensions' ),
|
||||
'BUSINESS' => __( 'Business', 'activitypub-event-extensions' ),
|
||||
'CAUSES' => __( 'Causes', 'activitypub-event-extensions' ),
|
||||
'COMEDY' => __( 'Comedy', 'activitypub-event-extensions' ),
|
||||
'CRAFTS' => __( 'Crafts', 'activitypub-event-extensions' ),
|
||||
'FOOD_DRINK' => __( 'Food & Drink', 'activitypub-event-extensions' ),
|
||||
'HEALTH' => __( 'Health', 'activitypub-event-extensions' ),
|
||||
'MUSIC' => __( 'Music', 'activitypub-event-extensions' ),
|
||||
'AUTO_BOAT_AIR' => __( 'Auto, boat and air', 'activitypub-event-extensions' ),
|
||||
'COMMUNITY' => __( 'Community', 'activitypub-event-extensions' ),
|
||||
'FAMILY_EDUCATION' => __( 'Family & Education', 'activitypub-event-extensions' ),
|
||||
'FASHION_BEAUTY' => __( 'Fashion & Beauty', 'activitypub-event-extensions' ),
|
||||
'FILM_MEDIA' => __( 'Film & Media', 'activitypub-event-extensions' ),
|
||||
'GAMES' => __( 'Games', 'activitypub-event-extensions' ),
|
||||
'LANGUAGE_CULTURE' => __( 'Language & Culture', 'activitypub-event-extensions' ),
|
||||
'LEARNING' => __( 'Learning', 'activitypub-event-extensions' ),
|
||||
'LGBTQ' => __( 'LGBTQ', 'activitypub-event-extensions' ),
|
||||
'MOVEMENTS_POLITICS' => __( 'Movements and politics', 'activitypub-event-extensions' ),
|
||||
'NETWORKING' => __( 'Networking', 'activitypub-event-extensions' ),
|
||||
'PARTY' => __( 'Party', 'activitypub-event-extensions' ),
|
||||
'PERFORMING_VISUAL_ARTS' => __( 'Performing & Visual Arts', 'activitypub-event-extensions' ),
|
||||
'PETS' => __( 'Pets', 'activitypub-event-extensions' ),
|
||||
'PHOTOGRAPHY' => __( 'Photography', 'activitypub-event-extensions' ),
|
||||
'OUTDOORS_ADVENTURE' => __( 'Outdoors & Adventure', 'activitypub-event-extensions' ),
|
||||
'SPIRITUALITY_RELIGION_BELIEFS' => __( 'Spirituality, Religion & Beliefs', 'activitypub-event-extensions' ),
|
||||
'SCIENCE_TECH' => __( 'Science & Tech', 'activitypub-event-extensions' ),
|
||||
'SPORTS' => __( 'Sports', 'activitypub-event-extensions' ),
|
||||
'THEATRE' => __( 'Theatre', 'activitypub-event-extensions' ),
|
||||
'MEETING' => __( 'Meeting', 'activitypub-event-extensions' ), // Default value in federation.
|
||||
'DEFAULT' => __( 'Default', 'activitypub-event-extensions' ), // Internal default for overrides.
|
||||
);
|
||||
|
||||
$selected_default_event_category = \get_option( 'activitypub_event_extensions_default_event_category', 'MEETING' );
|
||||
$current_category_mapping = \get_option( 'activitypub_event_extensions_event_category_mappings', array() );
|
||||
?>
|
||||
|
||||
<div class="activitypub-settings activitypub-settings-page hide-if-no-js">
|
||||
<form method="post" action="options.php">
|
||||
<?php \settings_fields( 'activitypub-event-extensions' ); ?>
|
||||
|
||||
<div class="box">
|
||||
|
||||
<h2> <?php esc_html_e( 'Default ActivityPub Event Category', 'activitypub-event-extensions' ); ?> </h2>
|
||||
|
||||
<p> <?php esc_html_e( 'The community defined an arbitrary set of basic event categories in order to allow events from multiple organizers to be grouped in a useful way. Please specify the category most common for your events.' ); ?> </p>
|
||||
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th scope="row"> <?php esc_html_e( 'Default Category', 'activitypub-event-extensions' ); ?> </th>
|
||||
<td>
|
||||
<select id="activitypub_event_extensions_default_event_category" name="activitypub_event_extensions_default_event_category">';
|
||||
<?php
|
||||
foreach ( $default_event_category_strings as $value => $label ) {
|
||||
echo '<option value="' . esc_attr( $value ) . '" ' . selected( $selected_default_event_category, $value, false ) . '>' . esc_html( $label ) . '</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2> <?php esc_html_e( 'Specific mapping of Event Categories', 'activitypub-event-extensions' ); ?> </h2>
|
||||
|
||||
<p> <?php esc_html_e( 'Here you can assign each of your event categories in use to the basic category set used in ActivityPub .' ); ?> </p>
|
||||
|
||||
<table class="form-table">
|
||||
<?php foreach ( $event_terms as $event_term ) { ?>
|
||||
<tr>
|
||||
<th scope="row"> <?php echo esc_html( $event_term->name ); ?> </th>
|
||||
<td>
|
||||
<select name="activitypub_event_extensions_event_category_mappings[<?php echo esc_attr( $event_term->slug ); ?>]">
|
||||
<?php
|
||||
$current_mapping_is_set = false;
|
||||
if ( ! empty( $current_category_mapping ) ) {
|
||||
$current_mapping_is_set = array_key_exists( $event_term->slug, $current_category_mapping );
|
||||
}
|
||||
if ( $current_mapping_is_set ) {
|
||||
$mapping = $current_category_mapping[ $event_term->slug ];
|
||||
} else {
|
||||
$mapping = 'DEFAULT';
|
||||
}
|
||||
if ( 'DEFAULT' === $mapping ) {
|
||||
echo '<option value="' . esc_attr( $mapping ) . '"> -- ' . esc_html( $default_event_category_strings[ $mapping ] ) . ' -- </option>';
|
||||
} else {
|
||||
echo '<option value="' . esc_attr( $mapping ) . '">' . esc_html( $default_event_category_strings[ $mapping ] ) . '</option>';
|
||||
}
|
||||
echo '<option value="DEFAULT" ' . selected( $selected_default_event_category, 'DEFAULT', false ) . '> -- ' . esc_html__( 'Default', 'activitypub-event-extensions' ) . ' -- </option>';
|
||||
foreach ( Event::DEFAULT_EVENT_CATEGORIES as $event_category ) {
|
||||
echo '<option value="' . esc_attr( $event_category ) . '" ' . selected( $mappings[ $event_term->slug ] ?? '', $event_category, false ) . '>' . esc_html( $default_event_category_strings[ $event_category ] ) . '</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</table>
|
||||
</div>
|
||||
<?php \submit_button(); ?>
|
||||
</form>
|
||||
</div>
|
Loading…
Reference in a new issue