PluginProbe
ActivityPub / 5.7.0
ActivityPub v5.7.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
← All changes | includes/handler/class-announce.php +31 -39 8.2.15.7.0 View file →
@@ -6,16 +6,14 @@
6 6 */
7 7
8 8 namespace Activitypub\Handler;
9 9
10 -use Activitypub\Collection\Actors;
10 +use Activitypub\Http;
11 +use Activitypub\Comment;
11 12 use Activitypub\Collection\Interactions;
12 -use Activitypub\Comment;
13 -use Activitypub\Http;
14 13
15 -use function Activitypub\is_activity;
14 +use function Activitypub\object_to_uri;
16 15 use function Activitypub\is_activity_public;
17 -use function Activitypub\object_to_uri;
18 16
19 17 /**
20 18 * Handle Create requests.
21 19 */
@@ -23,9 +21,14 @@
23 21 /**
24 22 * Initialize the class, registering WordPress hooks.
25 23 */
26 24 public static function init() {
27 - \add_action( 'activitypub_inbox_announce', array( self::class, 'handle_announce' ), 10, 3 );
25 + \add_action(
26 + 'activitypub_inbox_announce',
27 + array( self::class, 'handle_announce' ),
28 + 10,
29 + 3
30 + );
28 31 }
29 32
30 33 /**
31 34 * Handles "Announce" requests.
@@ -30,12 +33,12 @@
30 33 /**
31 34 * Handles "Announce" requests.
32 35 *
33 36 * @param array $announcement The activity-object.
34 - * @param int|int[] $user_ids The id(s) of the local blog-user(s).
37 + * @param int $user_id The id of the local blog-user.
35 38 * @param \Activitypub\Activity\Activity $activity The activity object.
36 39 */
37 - public static function handle_announce( $announcement, $user_ids, $activity = null ) {
40 + public static function handle_announce( $announcement, $user_id, $activity = null ) {
38 41 // Check if Activity is public or not.
39 42 if ( ! is_activity_public( $announcement ) ) {
40 43 // @todo maybe send email
41 44 return;
@@ -40,19 +43,14 @@
40 43 // @todo maybe send email
41 44 return;
42 45 }
43 46
44 - // Ignore announces from the blog actor.
45 - if ( Actors::BLOG_USER_ID === Actors::get_id_by_resource( $announcement['actor'] ) ) {
46 - return;
47 - }
48 -
49 47 // Check if reposts are allowed.
50 48 if ( ! Comment::is_comment_type_enabled( 'repost' ) ) {
51 49 return;
52 50 }
53 51
54 - self::maybe_save_announce( $announcement, $user_ids );
52 + self::maybe_save_announce( $announcement, $user_id );
55 53
56 54 if ( is_string( $announcement['object'] ) ) {
57 55 $object = Http::get_remote_object( $announcement['object'] );
58 56 } else {
@@ -62,9 +60,9 @@
62 60 if ( ! $object || is_wp_error( $object ) ) {
63 61 return;
64 62 }
65 63
66 - if ( ! is_activity( $object ) ) {
64 + if ( ! isset( $object['type'] ) ) {
67 65 return;
68 66 }
69 67
70 68 $type = \strtolower( $object['type'] );
@@ -72,32 +70,32 @@
72 70 /**
73 71 * Fires after an Announce has been received.
74 72 *
75 73 * @param array $object The object.
76 - * @param int[] $user_ids The ids of the local blog-users.
74 + * @param int $user_id The id of the local blog-user.
77 75 * @param string $type The type of the activity.
78 76 * @param \Activitypub\Activity\Activity|null $activity The activity object.
79 77 */
80 - \do_action( 'activitypub_inbox', $object, (array) $user_ids, $type, $activity );
78 + \do_action( 'activitypub_inbox', $object, $user_id, $type, $activity );
81 79
82 80 /**
83 81 * Fires after an Announce of a specific type has been received.
84 82 *
85 83 * @param array $object The object.
86 - * @param int[] $user_ids The ids of the local blog-users.
84 + * @param int $user_id The id of the local blog-user.
87 85 * @param \Activitypub\Activity\Activity|null $activity The activity object.
88 86 */
89 - \do_action( "activitypub_inbox_{$type}", $object, (array) $user_ids, $activity );
87 + \do_action( "activitypub_inbox_{$type}", $object, $user_id, $activity );
90 88 }
91 89
92 90 /**
93 91 * Try to save the Announce.
94 92 *
95 - * @param array $activity The activity-object.
96 - * @param int|int[] $user_ids The id of the local blog-user.
93 + * @param array $activity The activity-object.
94 + * @param int $user_id The id of the local blog-user.
97 95 */
98 - public static function maybe_save_announce( $activity, $user_ids ) {
99 - $url = object_to_uri( $activity );
96 + public static function maybe_save_announce( $activity, $user_id ) {
97 + $url = object_to_uri( $activity['object'] );
100 98
101 99 if ( empty( $url ) ) {
102 100 return;
103 101 }
@@ -106,28 +104,22 @@
106 104 if ( $exists ) {
107 105 return;
108 106 }
109 107
110 - // If the object is a Create activity, extract the actual object from it.
111 - if ( isset( $activity['object']['type'] ) && 'Create' === $activity['object']['type'] ) {
112 - $activity['object'] = object_to_uri( $activity['object']['object'] );
113 - }
108 + $state = Interactions::add_reaction( $activity );
109 + $reaction = null;
114 110
115 - $success = false;
116 - $result = Interactions::add_reaction( $activity );
117 -
118 - if ( $result && ! is_wp_error( $result ) ) {
119 - $success = true;
120 - $result = get_comment( $result );
111 + if ( $state && ! is_wp_error( $state ) ) {
112 + $reaction = get_comment( $state );
121 113 }
122 114
123 115 /**
124 - * Fires after an ActivityPub Announce activity has been handled.
116 + * Fires after an Announce has been saved.
125 117 *
126 - * @param array $activity The ActivityPub activity data.
127 - * @param int[] $user_ids The local user IDs.
128 - * @param bool $success True on success, false otherwise.
129 - * @param array|string|int|\WP_Error|false $result The WP_Comment object of the created announce/repost comment, or null if creation failed.
118 + * @param array $activity The activity-object.
119 + * @param int $user_id The id of the local blog-user.
120 + * @param mixed $state The state of the reaction.
121 + * @param mixed $reaction The reaction.
130 122 */
131 - \do_action( 'activitypub_handled_announce', $activity, (array) $user_ids, $success, $result );
123 + do_action( 'activitypub_handled_announce', $activity, $user_id, $state, $reaction );
132 124 }
133 125 }