PluginProbe
ActivityPub / 1.3.0
ActivityPub v1.3.0
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
activitypub / includes / handler / class-update.php

class-update.php in ActivityPub 1.3.0, at includes/handler/class-update.php

90 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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( 'activitypub_inbox_update', array( self::class, 'handle_update' ), 10, 2 );
18 }
19
20 /**
21 * Handle "Update" requests
22 *
23 * @param array $array The activity-object
24 * @param int $user_id The id of the local blog-user
25 */
26 public static function handle_update( $array, $user_id ) {
27 $object_type = isset( $array['object']['type'] ) ? $array['object']['type'] : '';
28
29 switch ( $object_type ) {
30 // Actor Types
31 // @see https://www.w3.org/TR/activitystreams-vocabulary/#actor-types
32 case 'Person':
33 case 'Group':
34 case 'Organization':
35 case 'Service':
36 case 'Application':
37 self::update_actor( $array );
38 break;
39 // Object and Link Types
40 // @see https://www.w3.org/TR/activitystreams-vocabulary/#object-types
41 case 'Note':
42 case 'Article':
43 case 'Image':
44 case 'Audio':
45 case 'Video':
46 case 'Event':
47 case 'Document':
48 self::update_interaction( $array, $user_id );
49 break;
50 // Minimal Activity
51 // @see https://www.w3.org/TR/activitystreams-core/#example-1
52 default:
53 break;
54 }
55 }
56
57 /**
58 * Update an Interaction
59 *
60 * @param array $activity The activity-object
61 * @param int $user_id The id of the local blog-user
62 *
63 * @return void
64 */
65 public static function update_interaction( $activity, $user_id ) {
66 $state = Interactions::update_comment( $activity );
67 $reaction = null;
68
69 if ( $state && ! \is_wp_error( $reaction ) ) {
70 $reaction = \get_comment( $state );
71 }
72
73 \do_action( 'activitypub_handled_update', $activity, $user_id, $state, $reaction );
74 }
75
76 /**
77 * Update an Actor
78 *
79 * @param array $activity The activity-object
80 *
81 * @return void
82 */
83 public static function update_actor( $activity ) {
84 // update cache
85 get_remote_metadata_by_actor( $activity['actor'], false );
86
87 // @todo maybe also update all interactions
88 }
89 }
90