2024-12-08 21:57:53 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Delete handler file.
|
|
|
|
*
|
|
|
|
* @package Event_Bridge_For_ActivityPub
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Event_Bridge_For_ActivityPub\ActivityPub\Handler;
|
|
|
|
|
|
|
|
use Activitypub\Collection\Actors;
|
2024-12-14 14:46:00 +01:00
|
|
|
use Event_Bridge_For_ActivityPub\Setup;
|
2024-12-16 17:36:23 +01:00
|
|
|
use Event_Bridge_For_ActivityPub\ActivityPub\Handler;
|
2024-12-08 21:57:53 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle Delete requests.
|
|
|
|
*/
|
|
|
|
class Delete {
|
|
|
|
/**
|
2024-12-16 17:36:23 +01:00
|
|
|
* Initialize the class, registering the handler for incoming `Delete` activities to the ActivityPub plugin.
|
2024-12-08 21:57:53 +01:00
|
|
|
*/
|
|
|
|
public static function init() {
|
|
|
|
\add_action(
|
|
|
|
'activitypub_inbox_delete',
|
2024-12-14 14:46:00 +01:00
|
|
|
array( self::class, 'handle_delete' ),
|
|
|
|
15,
|
|
|
|
2
|
2024-12-08 21:57:53 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle "Follow" requests.
|
|
|
|
*
|
2024-12-14 14:46:00 +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-14 14:46:00 +01:00
|
|
|
public static function handle_delete( $activity, $user_id ) {
|
|
|
|
// 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 ) {
|
2024-12-08 21:57:53 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-12-16 17:36:23 +01:00
|
|
|
if ( ! Handler::actor_is_event_source( $activity['actor'] ) ) {
|
2024-12-14 14:46:00 +01:00
|
|
|
return;
|
|
|
|
}
|
2024-12-08 21:57:53 +01:00
|
|
|
|
2024-12-14 14:46:00 +01:00
|
|
|
// Check if an object is set.
|
|
|
|
if ( ! isset( $activity['object']['type'] ) || 'Event' !== $activity['object']['type'] ) {
|
2024-12-08 21:57:53 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-12-16 17:36:23 +01:00
|
|
|
if ( Handler::is_time_passed( $activity['object']['startTime'] ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-12-15 23:55:13 +01:00
|
|
|
$transmogrifier = Setup::get_transmogrifier();
|
2024-12-14 14:46:00 +01:00
|
|
|
|
2024-12-15 23:55:13 +01:00
|
|
|
if ( ! $transmogrifier ) {
|
2024-12-08 21:57:53 +01:00
|
|
|
return;
|
|
|
|
}
|
2024-12-14 14:46:00 +01:00
|
|
|
|
2024-12-15 23:55:13 +01:00
|
|
|
$transmogrifier->delete( $activity['object'] );
|
2024-12-08 21:57:53 +01:00
|
|
|
}
|
|
|
|
}
|