PluginProbe
ActivityPub / 4.1.0
ActivityPub v4.1.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 4.1.0, at includes/handler/class-update.php

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