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

@ -13,7 +13,7 @@
namespace Event_Bridge_For_ActivityPub;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
\defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
use Activitypub\Http;
use Event_Bridge_For_ActivityPub\ActivityPub\Model\Event_Source;
@ -31,7 +31,7 @@ class Outbox_Parser {
/**
* Maximum number of events to backfill per actor.
*/
const MAX_EVENTS_TO_IMPORT = 20;
public const MAX_EVENTS_TO_IMPORT = 20;
/**
* Init actions.
@ -48,7 +48,7 @@ class Outbox_Parser {
* @param int $event_source_post_id The Post ID of Event Source we want to backfill the events for.
* @return void
*/
public static function backfill_events( $event_source_post_id ): void {
public static function backfill_events( int $event_source_post_id ): void {
$event_source = Event_Source::get_by_id( $event_source_post_id );
if ( ! $event_source ) {
@ -72,12 +72,7 @@ class Outbox_Parser {
* @param int $event_source_post_id The Post ID of the Event Source that owns the outbox.
* @return void
*/
public static function import_events_from_outbox( $url, $event_source_post_id ) {
$setup = Setup::get_instance();
if ( ! $setup->is_activitypub_plugin_active() ) {
return;
}
public static function import_events_from_outbox( string $url, int $event_source_post_id ): void {
$outbox = self::fetch_outbox( $url );
if ( ! $outbox ) {
@ -91,7 +86,7 @@ class Outbox_Parser {
}
// Process orderedItems if they exist (non-paginated outbox).
if ( isset( $outbox['orderedItems'] ) && is_array( $outbox['orderedItems'] ) ) {
if ( isset( $outbox['orderedItems'] ) && \is_array( $outbox['orderedItems'] ) ) {
$current_count += self::import_events_from_items(
$outbox['orderedItems'],
$event_source_post_id,
@ -120,11 +115,11 @@ class Outbox_Parser {
* @param array $activity The Activity as associative array.
* @return bool
*/
private static function is_create_or_update_activity( $activity ) {
private static function is_create_or_update_activity( array $activity ): bool {
if ( ! isset( $activity['type'] ) ) {
return false;
}
if ( in_array( $activity['type'], array( 'Update', 'Create' ), true ) ) {
if ( \in_array( $activity['type'], array( 'Update', 'Create' ), true ) ) {
return true;
}
return false;
@ -137,12 +132,12 @@ class Outbox_Parser {
* @param int $max_items The maximum number of items to parse.
* @return array Parsed events from the collection.
*/
private static function parse_outbox_items_for_events( $items, $max_items ) {
private static function parse_outbox_items_for_events( array $items, int $max_items ): array {
$parsed_events = array();
foreach ( $items as $activity ) {
// Abort if we have exceeded the maximal events to return.
if ( $max_items > 0 && count( $parsed_events ) >= $max_items ) {
if ( $max_items > 0 && \count( $parsed_events ) >= $max_items ) {
break;
}
@ -179,7 +174,7 @@ class Outbox_Parser {
* @param int $limit The limit of how many events to save locally.
* @return int The number of saved events (at least attempted).
*/
private static function import_events_from_items( $items, $event_source_post_id, $limit = -1 ): int {
private static function import_events_from_items( array $items, int $event_source_post_id, int $limit = -1 ): int {
$events = self::parse_outbox_items_for_events( $items, $limit );
$transmogrifier = Setup::get_transmogrifier();
@ -209,7 +204,7 @@ class Outbox_Parser {
* @param int $delay The delay of the current time in seconds.
* @return bool
*/
private static function queue_importing_from_outbox( $url, $event_source_post_id, $delay = 10 ): bool {
private static function queue_importing_from_outbox( string $url, int $event_source_post_id, int $delay = 10 ): bool {
$hook = 'event_bridge_for_activitypub_import_events_from_outbox';
$args = array( $url, $event_source_post_id );
@ -237,7 +232,7 @@ class Outbox_Parser {
* @param int $count The new count of imported events.
* @return void
*/
private static function update_import_count( $event_source_post_id, $count ) {
private static function update_import_count( int $event_source_post_id, int $count ): void {
\update_post_meta( $event_source_post_id, '_event_bridge_for_activitypub_event_count', $count );
}
@ -247,7 +242,7 @@ class Outbox_Parser {
* @param string $url The URL of the outbox.
* @return array|null The decoded outbox data, or null if fetching fails.
*/
private static function fetch_outbox( $url ) {
private static function fetch_outbox( string $url ): ?array {
$response = Http::get( $url );
if ( \is_wp_error( $response ) ) {
@ -266,9 +261,9 @@ class Outbox_Parser {
* @param array $outbox The outbox data.
* @return string|null The pagination URL, or null if not found.
*/
private static function get_pagination_url( $outbox ) {
private static function get_pagination_url( array $outbox ): ?string {
// If we are on a collection page simply use the next key.
if ( 'OrderedCollectionPage' === $outbox['type'] && ! empty( $outbox['next'] ) && is_string( $outbox['next'] ) ) {
if ( 'OrderedCollectionPage' === $outbox['type'] && ! empty( $outbox['next'] ) && \is_string( $outbox['next'] ) ) {
return $outbox['next'];
}