Compare commits

..

1 commit

Author SHA1 Message Date
df2867a89a code beautify and some better docs 2024-09-11 07:59:53 +02:00
14 changed files with 72 additions and 98 deletions

View file

@ -11,7 +11,7 @@
* License URI: https://www.gnu.org/licenses/agpl-3.0.de.html
* Requires PHP: 8.1
*
* Requires at least ActivityPub plugin with version >= 3.2.2. ActivityPub plugin tested up to: 3.2.2.
* ActivityPub plugin tested up to: 3.2.2
*
* @package activitypub-event-extensions
* @license AGPL-3.0-or-later
@ -26,7 +26,6 @@ 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';

View file

@ -2,13 +2,14 @@
/**
* Replace the default ActivityPub Transformer
*
* @package Activitypub_Event_Extensions
* @package activity-event-transformers
* @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;
@ -46,21 +47,10 @@ class Event extends Post {
*
* @return string The Event Object-Type.
*/
protected function get_type() {
protected function get_object_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.
*
@ -112,11 +102,12 @@ 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',
$this->get_actor_object()->get_followers(),
get_rest_url_by_path( $path ),
)
);

View file

@ -2,7 +2,7 @@
/**
* ActivityPub Transformer for the plugin Very Simple Event List.
*
* @package Activitypub_Event_Extensions
* @package activity-event-transformers
* @license AGPL-3.0-or-later
*/
@ -71,6 +71,17 @@ 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
*

View file

@ -2,7 +2,7 @@
/**
* ActivityPub Transformer for the plugin Very Simple Event List.
*
* @package Activitypub_Event_Extensions
* @package activity-event-transformers
* @license AGPL-3.0-or-later
*/
@ -85,6 +85,17 @@ 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.
*

View file

@ -2,7 +2,7 @@
/**
* ActivityPub Tribe Transformer
*
* @package Activitypub_Event_Extensions
* @package activity-event-transformers
* @license AGPL-3.0-or-later
*/
@ -62,22 +62,6 @@ 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
*

View file

@ -2,7 +2,7 @@
/**
* ActivityPub Transformer for the plugin Very Simple Event List.
*
* @package Activitypub_Event_Extensions
* @package activity-event-transformers
* @license AGPL-3.0-or-later
*/
@ -48,6 +48,32 @@ 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.
*

View file

@ -49,31 +49,14 @@ class General_Admin_Notices {
*/
public static function get_admin_notice_activitypub_plugin_not_enabled(): string {
return sprintf(
/* translators: 1: An URL that points to the ActivityPub plugin. */
/* translators: 1: the name of the event plugin a admin notice is shown. 2: The name of 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 ),
esc_html( ACTIVITYPUB_EVENT_EXTENSIONS_ACTIVITYPUB_PLUGIN_MIN_VERSION )
admin_url( 'options-general.php?page=activitypub&tab=settings' )
);
}
@ -84,14 +67,15 @@ class General_Admin_Notices {
*/
public static function get_admin_notice_no_supported_event_plugin_active(): string {
return sprintf(
/* translators: 1: An URL to the list of supported event plugins. */
/* translators: 1: the name of the event plugin a admin notice is shown. 2: The name of the ActivityPub plugin. */
_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 )
esc_html( self::ACTIVITYPUB_EVENT_EXTENSIONS_SUPPORTED_EVENT_PLUGINS_URL ),
admin_url( 'options-general.php?page=activitypub&tab=settings' )
);
}
@ -105,16 +89,6 @@ 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.
*

View file

@ -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_event_category_taxonomy();
$taxonomy = $event_plugin::get_taxonomy();
if ( $taxonomy ) {
$event_terms = get_terms(
array(

View file

@ -37,13 +37,6 @@ 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.
*
@ -60,13 +53,7 @@ class Setup {
*/
protected function __construct() {
$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->activitypub_plugin_version = get_file_data( WP_PLUGIN_DIR . '/activitypub/activitypub.php', array( 'Version' ) )[0];
$this->setup_hooks();
}
@ -164,12 +151,6 @@ 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 );
}
@ -202,14 +183,11 @@ 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 );
@ -236,7 +214,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_event_category_taxonomy() );
return new $transformer_class( $wp_object, $event_plugin->get_taxonomy() );
}
}
}

View file

@ -42,7 +42,7 @@ abstract class Event_Plugin {
*
* @return string
*/
abstract public static function get_event_category_taxonomy(): string;
abstract public static function get_taxonomy(): string;
/**
* 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
*/
public static function get_event_category_taxonomy(): string {
public static function get_taxonomy(): string {
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
*/
public static function get_event_category_taxonomy(): string {
public static function get_taxonomy(): string {
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
*/
public static function get_event_category_taxonomy(): string {
public static function get_taxonomy(): string {
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
*/
public static function get_event_category_taxonomy(): string {
public static function get_taxonomy(): string {
return 'event_cat';
}
}