Compare commits
5 commits
class_plug
...
main
Author | SHA1 | Date | |
---|---|---|---|
c8fc78ccdd | |||
4e2c1fb23a | |||
0b3974b255 | |||
1f2bf14860 | |||
126327288f |
14 changed files with 98 additions and 72 deletions
|
@ -11,7 +11,7 @@
|
|||
* License URI: https://www.gnu.org/licenses/agpl-3.0.de.html
|
||||
* 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
|
||||
* @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_VERSION', current( get_file_data( __FILE__, array( 'Version' ), 'plugin' ) ) );
|
||||
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.
|
||||
require_once ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_DIR . '/includes/class-autoloader.php';
|
||||
|
|
|
@ -2,14 +2,13 @@
|
|||
/**
|
||||
* Replace the default ActivityPub Transformer
|
||||
*
|
||||
* @package activity-event-transformers
|
||||
* @package Activitypub_Event_Extensions
|
||||
* @license AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace Activitypub_Event_Extensions\Activitypub\Transformer;
|
||||
|
||||
use Activitypub\Activity\Extended_Object\Event as Event_Object;
|
||||
use Activitypub\Model\Blog;
|
||||
use Activitypub\Transformer\Post;
|
||||
|
||||
use function Activitypub\get_rest_url_by_path;
|
||||
|
@ -47,10 +46,21 @@ class Event extends Post {
|
|||
*
|
||||
* @return string The Event Object-Type.
|
||||
*/
|
||||
protected function get_object_type() {
|
||||
protected function get_type() {
|
||||
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.
|
||||
*
|
||||
|
@ -102,12 +112,11 @@ class Event extends Post {
|
|||
$this->get_locale() => $this->get_content(),
|
||||
)
|
||||
);
|
||||
$path = sprintf( 'actors/%d/followers', intval( $this->wp_object->post_author ) );
|
||||
|
||||
$activitypub_object->set_to(
|
||||
array(
|
||||
'https://www.w3.org/ns/activitystreams#Public',
|
||||
get_rest_url_by_path( $path ),
|
||||
$this->get_actor_object()->get_followers(),
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* ActivityPub Transformer for the plugin Very Simple Event List.
|
||||
*
|
||||
* @package activity-event-transformers
|
||||
* @package Activitypub_Event_Extensions
|
||||
* @license AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
|
@ -71,17 +71,6 @@ final class Events_Manager extends Event_Transformer {
|
|||
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
|
||||
*
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* ActivityPub Transformer for the plugin Very Simple Event List.
|
||||
*
|
||||
* @package activity-event-transformers
|
||||
* @package Activitypub_Event_Extensions
|
||||
* @license AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
|
@ -85,17 +85,6 @@ final class GatherPress extends Event {
|
|||
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.
|
||||
*
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* ActivityPub Tribe Transformer
|
||||
*
|
||||
* @package activity-event-transformers
|
||||
* @package Activitypub_Event_Extensions
|
||||
* @license AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
|
@ -62,6 +62,22 @@ final class The_Events_Calendar extends Event {
|
|||
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
|
||||
*
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* ActivityPub Transformer for the plugin Very Simple Event List.
|
||||
*
|
||||
* @package activity-event-transformers
|
||||
* @package Activitypub_Event_Extensions
|
||||
* @license AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
|
@ -48,32 +48,6 @@ final class VS_Event_List extends Event_Transformer {
|
|||
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.
|
||||
*
|
||||
|
|
|
@ -49,14 +49,31 @@ class General_Admin_Notices {
|
|||
*/
|
||||
public static function get_admin_notice_activitypub_plugin_not_enabled(): string {
|
||||
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(
|
||||
'For the ActivityPub Event Extensions to work, you will need to install and activate the <a href="%1$s">ActivityPub</a> plugin.',
|
||||
'admin notice',
|
||||
'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 ),
|
||||
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 {
|
||||
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(
|
||||
'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>.',
|
||||
'admin notice',
|
||||
'activitypub-event-extensions'
|
||||
),
|
||||
esc_html( self::ACTIVITYPUB_EVENT_EXTENSIONS_SUPPORTED_EVENT_PLUGINS_URL ),
|
||||
admin_url( 'options-general.php?page=activitypub&tab=settings' )
|
||||
esc_html( self::ACTIVITYPUB_EVENT_EXTENSIONS_SUPPORTED_EVENT_PLUGINS_URL )
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -89,6 +105,16 @@ class General_Admin_Notices {
|
|||
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.
|
||||
*
|
||||
|
|
|
@ -69,7 +69,7 @@ class Settings_Page {
|
|||
* @return array An array of Terms.
|
||||
*/
|
||||
private static function get_event_terms( $event_plugin ): array {
|
||||
$taxonomy = $event_plugin::get_taxonomy();
|
||||
$taxonomy = $event_plugin::get_event_category_taxonomy();
|
||||
if ( $taxonomy ) {
|
||||
$event_terms = get_terms(
|
||||
array(
|
||||
|
|
|
@ -37,6 +37,13 @@ class Setup {
|
|||
*/
|
||||
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.
|
||||
*
|
||||
|
@ -53,7 +60,13 @@ class Setup {
|
|||
*/
|
||||
protected function __construct() {
|
||||
$this->activitypub_plugin_is_active = is_plugin_active( 'activitypub/activitypub.php' );
|
||||
$this->active_event_plugins = self::detect_active_event_plugins();
|
||||
// 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->activitypub_plugin_version = get_file_data( WP_PLUGIN_DIR . '/activitypub/activitypub.php', array( 'Version' ) )[0];
|
||||
$this->setup_hooks();
|
||||
}
|
||||
|
||||
|
@ -151,6 +164,12 @@ class Setup {
|
|||
'plugin_action_links_' . ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_BASENAME,
|
||||
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 );
|
||||
}
|
||||
|
||||
|
@ -183,11 +202,14 @@ class Setup {
|
|||
new Event_Plugin_Admin_Notices( $event_plugin );
|
||||
}
|
||||
// Check if any general admin notices are needed and add actions to insert the needed admin notices.
|
||||
|
||||
if ( ! $this->activitypub_plugin_is_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 );
|
||||
}
|
||||
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 ) ) {
|
||||
// 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 );
|
||||
|
@ -214,7 +236,7 @@ class Setup {
|
|||
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() );
|
||||
return new $transformer_class( $wp_object, $event_plugin->get_event_category_taxonomy() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ abstract class Event_Plugin {
|
|||
*
|
||||
* @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.
|
||||
|
|
|
@ -54,7 +54,7 @@ final class Events_Manager extends Event_Plugin {
|
|||
*
|
||||
* @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';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ final class GatherPress extends Event_Plugin {
|
|||
*
|
||||
* @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';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ final class The_Events_Calendar extends Event_plugin {
|
|||
*
|
||||
* @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';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ final class VS_Event_List extends Event_Plugin {
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_taxonomy(): string {
|
||||
public static function get_event_category_taxonomy(): string {
|
||||
return 'event_cat';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue