wordpress-activitypub/includes/handler/class-update.php
Konstantin Obenland a2e7729d4d
PHPCS: Enable NoReservedKeywordParameterNames sniff (#909)
* PHPCS: Enable NoReservedKeywordParameterNames sniff

* Fix parameter doc

Co-authored-by: Matthias Pfefferle <pfefferle@users.noreply.github.com>

* Rename to $data since the type is ambiguous

Props @pfefferle.

* Name it $uri for consistency

Props @pfefferle.

---------

Co-authored-by: Matthias Pfefferle <pfefferle@users.noreply.github.com>
2024-10-03 10:19:06 -05:00

94 lines
2.1 KiB
PHP

<?php
namespace Activitypub\Handler;
use WP_Error;
use Activitypub\Collection\Interactions;
use function Activitypub\get_remote_metadata_by_actor;
/**
* Handle Update requests.
*/
class Update {
/**
* Initialize the class, registering WordPress hooks
*/
public static function init() {
\add_action(
'activitypub_inbox_update',
array( self::class, 'handle_update' )
);
}
/**
* Handle "Update" requests
*
* @param array $activity The activity-object
*/
public static function handle_update( $activity ) {
$object_type = isset( $activity['object']['type'] ) ? $activity['object']['type'] : '';
switch ( $object_type ) {
// Actor Types
// @see https://www.w3.org/TR/activitystreams-vocabulary/#actor-types
case 'Person':
case 'Group':
case 'Organization':
case 'Service':
case 'Application':
self::update_actor( $activity );
break;
// Object and Link Types
// @see https://www.w3.org/TR/activitystreams-vocabulary/#object-types
case 'Note':
case 'Article':
case 'Image':
case 'Audio':
case 'Video':
case 'Event':
case 'Document':
self::update_interaction( $activity );
break;
// Minimal Activity
// @see https://www.w3.org/TR/activitystreams-core/#example-1
default:
break;
}
}
/**
* Update an Interaction
*
* @param array $activity The activity-object
* @param int $user_id The id of the local blog-user
*
* @return void
*/
public static function update_interaction( $activity ) {
$commentdata = Interactions::update_comment( $activity );
$reaction = null;
if ( ! empty( $commentdata['comment_ID'] ) ) {
$state = 1;
$reaction = \get_comment( $commentdata['comment_ID'] );
} else {
$state = $commentdata;
}
\do_action( 'activitypub_handled_update', $activity, null, $state, $reaction );
}
/**
* Update an Actor
*
* @param array $activity The activity-object
*
* @return void
*/
public static function update_actor( $activity ) {
// update cache
get_remote_metadata_by_actor( $activity['actor'], false );
// @todo maybe also update all interactions
}
}