André Menrath
ef1248beed
All checks were successful
PHP Code Checker / PHP Code Checker (pull_request) Successful in 55s
PHPUnit / PHPUnit – PHP 7.4 (pull_request) Successful in 1m10s
PHPUnit / PHPUnit – PHP 8.0 (pull_request) Successful in 1m7s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m6s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m9s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 1m3s
PHPUnit / PHPUnit – PHP 8.4 (pull_request) Successful in 1m9s
60 lines
1.3 KiB
PHP
60 lines
1.3 KiB
PHP
<?php
|
|
/**
|
|
* Create handler file.
|
|
*
|
|
* @package Event_Bridge_For_ActivityPub
|
|
*/
|
|
|
|
namespace Event_Bridge_For_ActivityPub\ActivityPub\Handler;
|
|
|
|
use Activitypub\Collection\Actors;
|
|
use Event_Bridge_For_ActivityPub\Setup;
|
|
|
|
use function Activitypub\is_activity_public;
|
|
|
|
/**
|
|
* 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.
|
|
*
|
|
* @param array $activity The activity-object.
|
|
* @param int $user_id The id of the local blog-user.
|
|
*/
|
|
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 ) {
|
|
return;
|
|
}
|
|
|
|
// Check if Activity is public or not.
|
|
if ( ! is_activity_public( $activity ) ) {
|
|
return;
|
|
}
|
|
|
|
// Check if an object is set.
|
|
if ( ! isset( $activity['object']['type'] ) || 'Event' !== isset( $activity['object']['type'] ) ) {
|
|
return;
|
|
}
|
|
|
|
$transmogrifier_class = Setup::get_transmogrifier();
|
|
|
|
if ( ! $transmogrifier_class ) {
|
|
return;
|
|
}
|
|
|
|
$transmogrifier = new $transmogrifier_class( $activity['object'] );
|
|
$transmogrifier->create();
|
|
}
|
|
}
|