wordpress-event-bridge-for-.../includes/activitypub/handler/class-create.php

71 lines
1.5 KiB
PHP
Raw Normal View History

<?php
/**
* Create handler file.
*
* @package Event_Bridge_For_ActivityPub
*/
namespace Event_Bridge_For_ActivityPub\ActivityPub\Handler;
use Activitypub\Collection\Actors;
2024-12-10 19:34:15 +01:00
use Event_Bridge_For_ActivityPub\Setup;
use Event_Bridge_For_ActivityPub\ActivityPub\Handler;
2024-12-10 19:34:15 +01:00
use function Activitypub\is_activity_public;
/**
* Handle Create requests.
*/
class Create {
/**
* Initialize the class, registering the handler for incoming `Create` activities to the ActivityPub plugin.
*/
public static function init() {
\add_action(
'activitypub_inbox_create',
2024-12-10 22:43:13 +01:00
array( self::class, 'handle_create' ),
15,
2
);
}
/**
* Handle incoming "Create" activities.
*
2024-12-10 19:34:15 +01:00
* @param array $activity The activity-object.
* @param int $user_id The id of the local blog-user.
*/
2024-12-10 19:34:15 +01:00
public static function handle_create( $activity, $user_id ) {
2024-12-11 23:09:12 +01:00
// We only process activities that are target to the application user.
2024-12-15 13:42:57 +01:00
if ( Actors::BLOG_USER_ID !== $user_id ) {
return;
}
if ( ! Handler::actor_is_event_source( $activity['actor'] ) ) {
2024-12-14 14:46:00 +01:00
return;
}
2024-12-10 19:34:15 +01:00
// Check if Activity is public or not.
if ( ! is_activity_public( $activity ) ) {
return;
}
2024-12-10 19:34:15 +01:00
// Check if an object is set.
2024-12-10 22:43:13 +01:00
if ( ! isset( $activity['object']['type'] ) || 'Event' !== $activity['object']['type'] ) {
return;
}
if ( Handler::is_time_passed( $activity['object']['startTime'] ) ) {
2024-12-15 09:52:20 +01:00
return;
}
$transmogrifier = Setup::get_transmogrifier();
2024-12-10 19:34:15 +01:00
if ( ! $transmogrifier ) {
return;
}
2024-12-10 19:34:15 +01:00
$transmogrifier->save( $activity['object'] );
}
}