Compare commits

...

5 commits

14 changed files with 111 additions and 79 deletions

View file

@ -11,7 +11,7 @@
* License URI: https://www.gnu.org/licenses/agpl-3.0.de.html * License URI: https://www.gnu.org/licenses/agpl-3.0.de.html
* Requires PHP: 8.1 * Requires PHP: 8.1
* *
* ActivityPub plugin tested up to: 3.2.2 * Requires at least ActivityPub plugin with version >= 3.2.2. 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
@ -26,6 +26,7 @@ define( 'ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_FILE', plugin_dir_path( __FILE__ )
define( 'ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); define( 'ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_VERSION', current( get_file_data( __FILE__, array( 'Version' ), 'plugin' ) ) ); define( 'ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_VERSION', current( get_file_data( __FILE__, array( 'Version' ), 'plugin' ) ) );
define( 'ACTIVITYPUB_EVENT_EXTENSIONS_DOMAIN', 'activitypub-event-extensions' ); define( 'ACTIVITYPUB_EVENT_EXTENSIONS_DOMAIN', 'activitypub-event-extensions' );
define( 'ACTIVITYPUB_EVENT_EXTENSIONS_ACTIVITYPUB_PLUGIN_MIN_VERSION', '3.2.2' );
// Include and register the autoloader class for automatic loading of plugin classes. // Include and register the autoloader class for automatic loading of plugin classes.
require_once ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_DIR . '/includes/class-autoloader.php'; require_once ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_DIR . '/includes/class-autoloader.php';

View file

@ -2,14 +2,13 @@
/** /**
* Replace the default ActivityPub Transformer * Replace the default ActivityPub Transformer
* *
* @package activity-event-transformers * @package Activitypub_Event_Extensions
* @license AGPL-3.0-or-later * @license AGPL-3.0-or-later
*/ */
namespace Activitypub_Event_Extensions\Activitypub\Transformer; namespace Activitypub_Event_Extensions\Activitypub\Transformer;
use Activitypub\Activity\Extended_Object\Event as Event_Object; use Activitypub\Activity\Extended_Object\Event as Event_Object;
use Activitypub\Model\Blog;
use Activitypub\Transformer\Post; use Activitypub\Transformer\Post;
use function Activitypub\get_rest_url_by_path; use function Activitypub\get_rest_url_by_path;
@ -47,10 +46,21 @@ class Event extends Post {
* *
* @return string The Event Object-Type. * @return string The Event Object-Type.
*/ */
protected function get_object_type() { protected function get_type() {
return 'Event'; return 'Event';
} }
/**
* Returns the title of the event.
*
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-name
*
* @return string The name.
*/
protected function get_name() {
return $this->wp_object->post_title;
}
/** /**
* Extend the construction of the Post Transformer to also set the according taxonomy of the event post type. * Extend the construction of the Post Transformer to also set the according taxonomy of the event post type.
* *
@ -102,12 +112,11 @@ class Event extends Post {
$this->get_locale() => $this->get_content(), $this->get_locale() => $this->get_content(),
) )
); );
$path = sprintf( 'actors/%d/followers', intval( $this->wp_object->post_author ) );
$activitypub_object->set_to( $activitypub_object->set_to(
array( array(
'https://www.w3.org/ns/activitystreams#Public', 'https://www.w3.org/ns/activitystreams#Public',
get_rest_url_by_path( $path ), $this->get_actor_object()->get_followers(),
) )
); );

View file

@ -2,7 +2,7 @@
/** /**
* ActivityPub Transformer for the plugin Very Simple Event List. * ActivityPub Transformer for the plugin Very Simple Event List.
* *
* @package activity-event-transformers * @package Activitypub_Event_Extensions
* @license AGPL-3.0-or-later * @license AGPL-3.0-or-later
*/ */
@ -71,17 +71,6 @@ final class Events_Manager extends Event_Transformer {
return array(); return array();
} }
/**
* Returns the ActivityStreams 2.0 Object-Type for an Event.
*
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-event
* @since 1.0.0
* @return string The Event Object-Type.
*/
protected function get_type() {
return 'Event';
}
/** /**
* Returns whether the even is online * Returns whether the even is online
* *

View file

@ -2,7 +2,7 @@
/** /**
* ActivityPub Transformer for the plugin Very Simple Event List. * ActivityPub Transformer for the plugin Very Simple Event List.
* *
* @package activity-event-transformers * @package Activitypub_Event_Extensions
* @license AGPL-3.0-or-later * @license AGPL-3.0-or-later
*/ */
@ -85,17 +85,6 @@ final class GatherPress extends Event {
return array( GatherPress_Event::POST_TYPE ); return array( GatherPress_Event::POST_TYPE );
} }
/**
* Returns the ActivityStreams 2.0 Object-Type for an Event.
*
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-event
* @since 1.0.0
* @return string The Event Object-Type.
*/
protected function get_type() {
return 'Event';
}
/** /**
* Get the event location. * Get the event location.
* *

View file

@ -2,7 +2,7 @@
/** /**
* ActivityPub Tribe Transformer * ActivityPub Tribe Transformer
* *
* @package activity-event-transformers * @package Activitypub_Event_Extensions
* @license AGPL-3.0-or-later * @license AGPL-3.0-or-later
*/ */
@ -62,6 +62,22 @@ final class The_Events_Calendar extends Event {
return $categories[0]; return $categories[0];
} }
/**
* Get the end time from the event object.
*/
protected function get_end_time() {
$date = date_create( $this->tribe_event->end_date, wp_timezone() );
return \gmdate( 'Y-m-d\TH:i:s\Z', $date->getTimestamp() );
}
/**
* Get the end time from the event object.
*/
protected function get_start_time() {
$date = date_create( $this->tribe_event->start_date, wp_timezone() );
return \gmdate( 'Y-m-d\TH:i:s\Z', $date->getTimestamp() );
}
/** /**
* Get status of the tribe event * Get status of the tribe event
* *

View file

@ -2,7 +2,7 @@
/** /**
* ActivityPub Transformer for the plugin Very Simple Event List. * ActivityPub Transformer for the plugin Very Simple Event List.
* *
* @package activity-event-transformers * @package Activitypub_Event_Extensions
* @license AGPL-3.0-or-later * @license AGPL-3.0-or-later
*/ */
@ -48,32 +48,6 @@ final class VS_Event_List extends Event_Transformer {
return 'activitypub-event-transformers/vs-event'; return 'activitypub-event-transformers/vs-event';
} }
/**
* Get transformer title.
*
* Retrieve the transformers label.
*
* @since 1.0.0
* @access public
* @return string Widget title.
*/
public function get_transformer_label(): string {
return 'VS Event';
}
/**
* Get supported post types.
*
* Retrieve the list of supported WordPress post types this transformer widget can handle.
*
* @since 1.0.0
* @access public
* @return array Widget categories.
*/
public static function get_supported_post_types(): string {
return array( 'event' );
}
/** /**
* Returns the ActivityStreams 2.0 Object-Type for an Event. * Returns the ActivityStreams 2.0 Object-Type for an Event.
* *

View file

@ -49,14 +49,31 @@ class General_Admin_Notices {
*/ */
public static function get_admin_notice_activitypub_plugin_not_enabled(): string { public static function get_admin_notice_activitypub_plugin_not_enabled(): string {
return sprintf( return sprintf(
/* translators: 1: the name of the event plugin a admin notice is shown. 2: The name of the ActivityPub plugin. */ /* translators: 1: An URL that points to the ActivityPub plugin. */
_x( _x(
'For the ActivityPub Event Extensions to work, you will need to install and activate the <a href="%1$s">ActivityPub</a> plugin.', 'For the ActivityPub Event Extensions to work, you will need to install and activate the <a href="%1$s">ActivityPub</a> plugin.',
'admin notice', 'admin notice',
'activitypub-event-extensions' 'activitypub-event-extensions'
), ),
esc_html( self::ACTIVITYPUB_PLUGIN_URL )
);
}
/**
* Admin notice when the ActivityPub plugin version is too old.
*
* @return string
*/
public static function get_admin_notice_activitypub_plugin_version_too_old(): string {
return sprintf(
/* translators: 1: The name of the ActivityPub plugin. 2: The minimum required version number of the ActivityPub plugin. */
_x(
'Please upgrade your <a href="%1$s">ActivityPub</a> plugin. At least version %2$s is required for the ActivityPub event extensions to work.',
'admin notice',
'activitypub-event-extensions'
),
esc_html( self::ACTIVITYPUB_PLUGIN_URL ), esc_html( self::ACTIVITYPUB_PLUGIN_URL ),
admin_url( 'options-general.php?page=activitypub&tab=settings' ) esc_html( ACTIVITYPUB_EVENT_EXTENSIONS_ACTIVITYPUB_PLUGIN_MIN_VERSION )
); );
} }
@ -67,15 +84,14 @@ class General_Admin_Notices {
*/ */
public static function get_admin_notice_no_supported_event_plugin_active(): string { public static function get_admin_notice_no_supported_event_plugin_active(): string {
return sprintf( return sprintf(
/* translators: 1: the name of the event plugin a admin notice is shown. 2: The name of the ActivityPub plugin. */ /* translators: 1: An URL to the list of supported event plugins. */
_x( _x(
'The Plugin <i>ActivityPub Event Extensions</i> is of no use, because you do not have installed and activated a supported Event Plugin. 'The Plugin <i>ActivityPub Event Extensions</i> is of no use, because you do not have installed and activated a supported Event Plugin.
<br> For a list of supported Event Plugins see <a href="%1$s">here</a>.', <br> For a list of supported Event Plugins see <a href="%1$s">here</a>.',
'admin notice', 'admin notice',
'activitypub-event-extensions' 'activitypub-event-extensions'
), ),
esc_html( self::ACTIVITYPUB_EVENT_EXTENSIONS_SUPPORTED_EVENT_PLUGINS_URL ), esc_html( self::ACTIVITYPUB_EVENT_EXTENSIONS_SUPPORTED_EVENT_PLUGINS_URL )
admin_url( 'options-general.php?page=activitypub&tab=settings' )
); );
} }
@ -89,6 +105,16 @@ class General_Admin_Notices {
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>';
} }
/**
* Warning if the plugin is Active and the ActivityPub plugins version is too old.
*
* @return void
*/
public static function activitypub_plugin_version_too_old(): void {
$notice = self::get_admin_notice_activitypub_plugin_version_too_old();
echo '<div class="notice notice-warning"><p>' . \wp_kses( $notice, self::ALLOWED_HTML ) . '</p></div>';
}
/** /**
* Warning when no supported Even Plugin is installed and active. * Warning when no supported Even Plugin is installed and active.
* *

View file

@ -18,9 +18,10 @@ use Activitypub_Event_Extensions\Plugins\Event_Plugin;
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
/** /**
* Class responsible for the ActivityPui Event Extension related Settings. * Class responsible for the ActivityPub Event Extension related Settings.
* *
* Class responsible for the ActivityPui Event Extension related Settings. * Class which handles the "General" settings page for the ActivityPub Event Extension Plugin,
* providing options for configuring various general settings.
* *
* @since 1.0.0 * @since 1.0.0
*/ */
@ -30,8 +31,10 @@ class Settings_Page {
const SETTINGS_SLUG = 'activitypub-event-extensions'; const SETTINGS_SLUG = 'activitypub-event-extensions';
/** /**
* Warning if the plugin is Active and the ActivityPub plugin is not. * Warning if the plugin is Active and the ActivityPub plugin is not.
*
* @return void
*/ */
public static function admin_menu() { public static function admin_menu(): void {
\add_options_page( \add_options_page(
'Activitypub Event Extension', 'Activitypub Event Extension',
__( 'ActivityPub Events', 'activitypub_event_extensions' ), __( 'ActivityPub Events', 'activitypub_event_extensions' ),
@ -46,9 +49,10 @@ class Settings_Page {
* It's called via apply_filter('plugin_action_links_' . PLUGIN_NAME). * It's called via apply_filter('plugin_action_links_' . PLUGIN_NAME).
* *
* @param array $links Already added links. * @param array $links Already added links.
*
* @return array Original links but with link to setting page added. * @return array Original links but with link to setting page added.
*/ */
public static function settings_link( $links ) { public static function settings_link( $links ): array {
return array_merge( return array_merge(
$links, $links,
array( array(
@ -64,8 +68,8 @@ class Settings_Page {
* *
* @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 ): array {
$taxonomy = $event_plugin::get_taxonomy(); $taxonomy = $event_plugin::get_event_category_taxonomy();
if ( $taxonomy ) { if ( $taxonomy ) {
$event_terms = get_terms( $event_terms = get_terms(
array( array(
@ -80,9 +84,11 @@ class Settings_Page {
} }
/** /**
* Settings page. * Preparing the data and loading the template for the settings page.
*
* @return void
*/ */
public static function settings_page() { public static function settings_page(): void {
$plugin_setup = Setup::get_instance(); $plugin_setup = Setup::get_instance();
$event_plugins = $plugin_setup->get_active_event_plugins(); $event_plugins = $plugin_setup->get_active_event_plugins();

View file

@ -37,6 +37,13 @@ class Setup {
*/ */
protected $activitypub_plugin_is_active = false; protected $activitypub_plugin_is_active = false;
/**
* Keep the current version of the current ActivityPub plugin.
*
* @var string
*/
protected $activitypub_plugin_version = '';
/** /**
* Holds an array of the currently activated supported event plugins. * Holds an array of the currently activated supported event plugins.
* *
@ -53,7 +60,13 @@ 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' );
// TODO: decide whether we want to do anything at all when ActivityPub plugin is note active.
// if ( ! $this->activitypub_plugin_is_active ) {
// deactivate_plugins( ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_FILE );
// return;
// }.
$this->active_event_plugins = self::detect_active_event_plugins(); $this->active_event_plugins = self::detect_active_event_plugins();
$this->activitypub_plugin_version = get_file_data( WP_PLUGIN_DIR . '/activitypub/activitypub.php', array( 'Version' ) )[0];
$this->setup_hooks(); $this->setup_hooks();
} }
@ -151,6 +164,12 @@ class Setup {
'plugin_action_links_' . ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_BASENAME, 'plugin_action_links_' . ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_BASENAME,
array( Settings_Page::class, 'settings_link' ) array( Settings_Page::class, 'settings_link' )
); );
// Check if the minimum required version of the ActivityPub plugin is installed.
if ( version_compare( $this->activitypub_plugin_version, ACTIVITYPUB_EVENT_EXTENSIONS_ACTIVITYPUB_PLUGIN_MIN_VERSION ) ) {
return;
}
add_filter( 'activitypub_transformer', array( $this, 'register_activitypub_event_transformer' ), 10, 3 ); add_filter( 'activitypub_transformer', array( $this, 'register_activitypub_event_transformer' ), 10, 3 );
} }
@ -183,11 +202,14 @@ class Setup {
new Event_Plugin_Admin_Notices( $event_plugin ); new Event_Plugin_Admin_Notices( $event_plugin );
} }
// Check if any general admin notices are needed and add actions to insert the needed admin notices. // Check if any general admin notices are needed and add actions to insert the needed admin notices.
if ( ! $this->activitypub_plugin_is_active ) { if ( ! $this->activitypub_plugin_is_active ) {
// The ActivityPub plugin is not active. // The ActivityPub plugin is not active.
add_action( 'admin_notices', array( 'Activitypub_Event_Extensions\Admin\General_Admin_Notices', 'activitypub_plugin_not_enabled' ), 10, 1 ); add_action( 'admin_notices', array( 'Activitypub_Event_Extensions\Admin\General_Admin_Notices', 'activitypub_plugin_not_enabled' ), 10, 1 );
} }
if ( version_compare( $this->activitypub_plugin_version, ACTIVITYPUB_EVENT_EXTENSIONS_ACTIVITYPUB_PLUGIN_MIN_VERSION ) ) {
// The ActivityPub plugin is too old.
add_action( 'admin_notices', array( 'Activitypub_Event_Extensions\Admin\General_Admin_Notices', 'activitypub_plugin_version_too_old' ), 10, 1 );
}
if ( empty( $this->active_event_plugins ) ) { if ( empty( $this->active_event_plugins ) ) {
// No supported Event Plugin is active. // No supported Event Plugin is active.
add_action( 'admin_notices', array( 'Activitypub_Event_Extensions\Admin\General_Admin_Notices', 'no_supported_event_plugin_active' ), 10, 1 ); add_action( 'admin_notices', array( 'Activitypub_Event_Extensions\Admin\General_Admin_Notices', 'no_supported_event_plugin_active' ), 10, 1 );
@ -214,7 +236,7 @@ class Setup {
if ( $wp_object->post_type === $event_plugin->get_post_type() ) { if ( $wp_object->post_type === $event_plugin->get_post_type() ) {
$transformer_class = $event_plugin->get_activitypub_event_transformer_class(); $transformer_class = $event_plugin->get_activitypub_event_transformer_class();
if ( class_exists( $transformer_class ) ) { if ( class_exists( $transformer_class ) ) {
return new $transformer_class( $wp_object, $event_plugin->get_taxonomy() ); return new $transformer_class( $wp_object, $event_plugin->get_event_category_taxonomy() );
} }
} }
} }

View file

@ -42,7 +42,7 @@ abstract class Event_Plugin {
* *
* @return string * @return string
*/ */
abstract public static function get_taxonomy(): string; abstract public static function get_event_category_taxonomy(): string;
/** /**
* Returns the ID of the main settings page of the plugin. * Returns the ID of the main settings page of the plugin.

View file

@ -54,7 +54,7 @@ final class Events_Manager extends Event_Plugin {
* *
* @return string * @return string
*/ */
public static function get_taxonomy(): string { public static function get_event_category_taxonomy(): string {
return defined( 'EM_TAXONOMY_CATEGORY' ) ? constant( 'EM_TAXONOMY_CATEGORY' ) : 'event-categories'; return defined( 'EM_TAXONOMY_CATEGORY' ) ? constant( 'EM_TAXONOMY_CATEGORY' ) : 'event-categories';
} }
} }

View file

@ -63,7 +63,7 @@ final class GatherPress extends Event_Plugin {
* *
* @return string * @return string
*/ */
public static function get_taxonomy(): string { public static function get_event_category_taxonomy(): string {
return class_exists( '\GatherPress\Core\Topic' ) ? \GatherPress\Core\Topic::TAXONOMY : 'gatherpress_topic'; return class_exists( '\GatherPress\Core\Topic' ) ? \GatherPress\Core\Topic::TAXONOMY : 'gatherpress_topic';
} }
} }

View file

@ -55,7 +55,7 @@ final class The_Events_Calendar extends Event_plugin {
* *
* @return string * @return string
*/ */
public static function get_taxonomy(): string { public static function get_event_category_taxonomy(): string {
return class_exists( '\Tribe__Events__Main' ) ? \Tribe__Events__Main::TAXONOMY : 'tribe_events_cat'; return class_exists( '\Tribe__Events__Main' ) ? \Tribe__Events__Main::TAXONOMY : 'tribe_events_cat';
} }
} }

View file

@ -66,7 +66,7 @@ final class VS_Event_List extends Event_Plugin {
* *
* @return string * @return string
*/ */
public static function get_taxonomy(): string { public static function get_event_category_taxonomy(): string {
return 'event_cat'; return 'event_cat';
} }
} }