updated plugin Event Bridge for ActivityPub version 1.3.0

This commit is contained in:
2026-06-03 21:28:57 +00:00
committed by Gitium
parent 1f3438440f
commit f2d6714572
84 changed files with 1721 additions and 1361 deletions

View File

@ -10,7 +10,7 @@
namespace Event_Bridge_For_ActivityPub;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
\defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
use Activitypub\Model\Blog;
use DateTime;
@ -34,7 +34,7 @@ class Event_Sources {
/**
* Init.
*/
public static function init() {
public static function init(): void {
// Register the Event Sources Collection which takes care of managing the event sources.
\add_action( 'init', array( Event_Sources_Collection::class, 'init' ) );
@ -87,7 +87,7 @@ class Event_Sources {
*
* @return void
*/
public static function register_post_meta() {
public static function register_post_meta(): void {
$setup = Setup::get_instance();
foreach ( $setup->get_active_event_plugins() as $event_plugin_integration ) {
@ -116,7 +116,7 @@ class Event_Sources {
* @param string $post_type The post type to register the meta for.
* @return void
*/
private static function register_post_meta_event_bridge_for_activitypub_event_source( $post_type ) {
private static function register_post_meta_event_bridge_for_activitypub_event_source( string $post_type ): void {
\register_post_meta(
$post_type,
'_event_bridge_for_activitypub_event_source',
@ -132,9 +132,9 @@ class Event_Sources {
* Get the Application actor via FEP-2677.
*
* @param string $domain The domain without scheme.
* @return bool|string The URL/ID of the application actor, false if not found.
* @return string|false The URL/ID of the application actor, false if not found.
*/
public static function get_application_actor( $domain ) {
public static function get_application_actor( string $domain ): string|false {
$result = wp_remote_get( 'https://' . $domain . '/.well-known/nodeinfo' );
if ( is_wp_error( $result ) ) {
@ -146,11 +146,11 @@ class Event_Sources {
$nodeinfo = json_decode( $body, true );
// Check if 'links' exists and is an array.
if ( isset( $nodeinfo['links'] ) && is_array( $nodeinfo['links'] ) ) {
if ( isset( $nodeinfo['links'] ) && \is_array( $nodeinfo['links'] ) ) {
foreach ( $nodeinfo['links'] as $link ) {
// Check if this link matches the application actor rel.
if ( isset( $link['rel'] ) && 'https://www.w3.org/ns/activitystreams#Application' === $link['rel'] ) {
if ( is_string( $link['href'] ) ) {
if ( \is_string( $link['href'] ) ) {
return $link['href'];
}
break;
@ -172,7 +172,7 @@ class Event_Sources {
* @param WP_Post $post The WordPress post object.
* @return bool False if the post is not disabled for federation via ActivityPub.
*/
public static function is_post_disabled_for_activitypub( $disabled, $post = null ): bool {
public static function is_post_disabled_for_activitypub( bool $disabled, WP_Post $post ): bool {
if ( $disabled ) {
return $disabled;
}
@ -185,7 +185,7 @@ class Event_Sources {
* @param WP_Post|int $post The WordPress post object or post ID.
* @return bool
*/
public static function is_cached_external_post( $post ): bool {
public static function is_cached_external_post( WP_Post|int $post ): bool {
$post_id = $post instanceof WP_Post ? $post->ID : $post;
if ( \get_post_meta( $post_id, '_event_bridge_for_activitypub_event_source', true ) ) {
@ -196,13 +196,13 @@ class Event_Sources {
}
/**
* Add the ActivityPub template for EventPrime.
* Maybe redirect cached external events to origin.
*
* @param string $template The path to the template object.
* @return string The new path to the JSON template.
*/
public static function redirect_activitypub_requests_for_cached_external_events( $template ) {
if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
public static function redirect_activitypub_requests_for_cached_external_events( string $template ) {
if ( \defined( 'REST_REQUEST' ) && REST_REQUEST ) {
return $template;
}
@ -259,7 +259,7 @@ class Event_Sources {
*
* @return array The array of following urls.
*/
public static function add_event_sources_to_follow_collection( $follow_list, $user ): array {
public static function add_event_sources_to_follow_collection( array $follow_list, mixed $user ): array {
if ( ! $user instanceof Blog ) {
return $follow_list;
}
@ -274,7 +274,7 @@ class Event_Sources {
*
* @return array A list with all unique hosts of all Event Sources' ActivityPub IDs.
*/
public static function get_event_sources_hosts() {
public static function get_event_sources_hosts(): array {
$hosts = get_transient( 'event_bridge_for_activitypub_event_sources_hosts' );
if ( $hosts ) {
@ -304,7 +304,7 @@ class Event_Sources {
* @param array $hosts The hosts before the filter.
* @return array
*/
public static function add_event_sources_hosts_to_allowed_redirect_hosts( $hosts ) {
public static function add_event_sources_hosts_to_allowed_redirect_hosts( array $hosts ): array {
$event_sources_hosts = self::get_event_sources_hosts();
return array_merge( $hosts, $event_sources_hosts );
}
@ -313,18 +313,18 @@ class Event_Sources {
* Mark incoming accept activities as valid.
*
* @param bool $valid The validation state.
* @param string $param The object parameter.
* @param mixed $param The object parameter.
* @param WP_REST_Request $request The request object.
*
* @return bool|WP_Error The validation state: true if valid, false if not.
*/
public static function validate_activity( $valid, $param, $request ) {
public static function validate_activity( bool $valid, mixed $param, WP_REST_Request $request ) {
if ( $valid ) {
return $valid;
}
$json_params = $request->get_json_params();
if ( isset( $json_params['object']['type'] ) && in_array( $json_params['object']['type'], array( 'Accept', 'Undo' ), true ) ) {
if ( isset( $json_params['object']['type'] ) && \in_array( $json_params['object']['type'], array( 'Accept', 'Undo' ), true ) ) {
return true;
}
@ -335,12 +335,12 @@ class Event_Sources {
* Validate the event object.
*
* @param bool $valid The validation state.
* @param string $param The object parameter.
* @param mixed $param The object parameter.
* @param WP_REST_Request $request The request object.
*
* @return bool|WP_Error The validation state: true if valid, false if not.
*/
public static function validate_event_object( $valid, $param, $request ) {
public static function validate_event_object( bool $valid, mixed $param, WP_REST_Request $request ): bool|WP_Error {
$json_params = $request->get_json_params();
// Check if we should continue with the validation.
@ -379,7 +379,7 @@ class Event_Sources {
* @param string ...$urls List of URLs to compare.
* @return bool True if all URLs have the same host, false otherwise.
*/
public static function same_host( ...$urls ) {
public static function same_host( string ...$urls ): bool {
if ( empty( $urls ) ) {
return false; // No URLs given, can't compare hosts.
}
@ -412,8 +412,8 @@ class Event_Sources {
* @param mixed $event_object The (event) object as an associative array.
* @return bool True if the object is an valid ActivityPub Event, false if not.
*/
public static function is_valid_activitypub_event_object( $event_object ): bool {
if ( ! is_array( $event_object ) ) {
public static function is_valid_activitypub_event_object( mixed $event_object ): bool {
if ( ! \is_array( $event_object ) ) {
return false;
}
@ -446,7 +446,7 @@ class Event_Sources {
* @param string $id The ID to validate.
* @return bool
*/
public static function is_valid_activitypub_id( $id ) {
public static function is_valid_activitypub_id( string $id ): bool {
return \sanitize_url( $id ) ? true : false;
}
@ -469,7 +469,7 @@ class Event_Sources {
* @param string|DateTime $time The ActivityPub like time string or DateTime object.
* @return bool
*/
public static function is_time_passed( $time ) {
public static function is_time_passed( string|DateTime $time ): bool {
if ( ! $time instanceof DateTime ) {
// Create a DateTime object from the ActivityPub time string.
$time = new DateTime( $time, new DateTimeZone( 'UTC' ) );
@ -488,7 +488,7 @@ class Event_Sources {
* @param array $event_object The ActivityPub Event as an associative array.
* @return bool
*/
public static function is_ongoing_or_future_event( $event_object ) {
public static function is_ongoing_or_future_event( array $event_object ): bool {
if ( isset( $event_object['endTime'] ) ) {
$time = $event_object['endTime'];
} else {
@ -504,9 +504,9 @@ class Event_Sources {
* @param string $actor_id The actor ID.
* @return bool True if the ActivityPub actor ID is followed, false otherwise.
*/
public static function actor_is_event_source( $actor_id ) {
public static function actor_is_event_source( string $actor_id ): bool {
$event_sources = Event_Sources_Collection::get_event_sources();
if ( in_array( $actor_id, $event_sources, true ) ) {
if ( \in_array( $actor_id, $event_sources, true ) ) {
return true;
}
return false;