| 1 |
<?php |
| 2 |
namespace Activitypub\Handler; |
| 3 |
|
| 4 |
use WP_Error; |
| 5 |
use Activitypub\Collection\Interactions; |
| 6 |
|
| 7 |
use function Activitypub\get_remote_metadata_by_actor; |
| 8 |
|
| 9 |
/** |
| 10 |
* Handle Update requests. |
| 11 |
*/ |
| 12 |
class Update { |
| 13 |
/** |
| 14 |
* Initialize the class, registering WordPress hooks |
| 15 |
*/ |
| 16 |
public static function init() { |
| 17 |
\add_action( |
| 18 |
'activitypub_inbox_update', |
| 19 |
array( self::class, 'handle_update' ) |
| 20 |
); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Handle "Update" requests |
| 25 |
* |
| 26 |
* @param array $array The activity-object |
| 27 |
* @param int $user_id The id of the local blog-user |
| 28 |
*/ |
| 29 |
public static function handle_update( $array ) { |
| 30 |
$object_type = isset( $array['object']['type'] ) ? $array['object']['type'] : ''; |
| 31 |
|
| 32 |
switch ( $object_type ) { |
| 33 |
// Actor Types |
| 34 |
// @see https://www.w3.org/TR/activitystreams-vocabulary/#actor-types |
| 35 |
case 'Person': |
| 36 |
case 'Group': |
| 37 |
case 'Organization': |
| 38 |
case 'Service': |
| 39 |
case 'Application': |
| 40 |
self::update_actor( $array ); |
| 41 |
break; |
| 42 |
// Object and Link Types |
| 43 |
// @see https://www.w3.org/TR/activitystreams-vocabulary/#object-types |
| 44 |
case 'Note': |
| 45 |
case 'Article': |
| 46 |
case 'Image': |
| 47 |
case 'Audio': |
| 48 |
case 'Video': |
| 49 |
case 'Event': |
| 50 |
case 'Document': |
| 51 |
self::update_interaction( $array ); |
| 52 |
break; |
| 53 |
// Minimal Activity |
| 54 |
// @see https://www.w3.org/TR/activitystreams-core/#example-1 |
| 55 |
default: |
| 56 |
break; |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Update an Interaction |
| 62 |
* |
| 63 |
* @param array $activity The activity-object |
| 64 |
* @param int $user_id The id of the local blog-user |
| 65 |
* |
| 66 |
* @return void |
| 67 |
*/ |
| 68 |
public static function update_interaction( $activity ) { |
| 69 |
$commentdata = Interactions::update_comment( $activity ); |
| 70 |
$reaction = null; |
| 71 |
|
| 72 |
if ( ! empty( $commentdata['comment_ID'] ) ) { |
| 73 |
$state = 1; |
| 74 |
$reaction = \get_comment( $commentdata['comment_ID'] ); |
| 75 |
} else { |
| 76 |
$state = $commentdata; |
| 77 |
} |
| 78 |
|
| 79 |
\do_action( 'activitypub_handled_update', $activity, null, $state, $reaction ); |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Update an Actor |
| 84 |
* |
| 85 |
* @param array $activity The activity-object |
| 86 |
* |
| 87 |
* @return void |
| 88 |
*/ |
| 89 |
public static function update_actor( $activity ) { |
| 90 |
// update cache |
| 91 |
get_remote_metadata_by_actor( $activity['actor'], false ); |
| 92 |
|
| 93 |
// @todo maybe also update all interactions |
| 94 |
} |
| 95 |
} |
| 96 |
|