2024-12-08 21:57:53 +01:00
|
|
|
<?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 function Activitypub\is_activity_public;
|
2024-12-08 21:57:53 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle Create requests.
|
|
|
|
*/
|
|
|
|
class Create {
|
|
|
|
/**
|
|
|
|
* Initialize the class, registering WordPress hooks.
|
|
|
|
*/
|
|
|
|
public static function init() {
|
|
|
|
\add_action(
|
|
|
|
'activitypub_inbox_create',
|
|
|
|
array( self::class, 'handle_create' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle "Create" requests.
|
|
|
|
*
|
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-08 21:57:53 +01:00
|
|
|
*/
|
2024-12-10 19:34:15 +01:00
|
|
|
public static function handle_create( $activity, $user_id ) {
|
|
|
|
// We only process activities that are target the application user.
|
|
|
|
if ( Actors::APPLICATION_USER_ID !== $user_id ) {
|
2024-12-08 21:57:53 +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-08 21:57:53 +01:00
|
|
|
|
2024-12-10 19:34:15 +01:00
|
|
|
// Check if an object is set.
|
|
|
|
if ( ! isset( $activity['object']['type'] ) || 'Event' !== isset( $activity['object']['type'] ) ) {
|
2024-12-08 21:57:53 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-12-10 19:34:15 +01:00
|
|
|
$transmogrifier_class = Setup::get_transmogrifier();
|
|
|
|
|
|
|
|
if ( ! $transmogrifier_class ) {
|
2024-12-08 21:57:53 +01:00
|
|
|
return;
|
|
|
|
}
|
2024-12-10 19:34:15 +01:00
|
|
|
|
|
|
|
$transmogrifier = new $transmogrifier_class( $activity['object'] );
|
|
|
|
$transmogrifier->create();
|
2024-12-08 21:57:53 +01:00
|
|
|
}
|
|
|
|
}
|