PluginProbe
ActivityPub / 8.0.2
ActivityPub v8.0.2
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/functions-activity.php +18 -115 9.2.08.0.2 View file →
@@ -50,19 +50,9 @@
50 50 foreach ( array( 'to', 'bto', 'cc', 'bcc', 'audience' ) as $i ) {
51 51 $recipient_items = \array_merge( $recipient_items, extract_recipients_from_activity_property( $i, $data ) );
52 52 }
53 53
54 - // An Accept/Reject that wraps a Follow is addressed only through the embedded Follow's actor.
55 - if (
56 - \in_array( $data['type'], array( 'Accept', 'Reject' ), true ) &&
57 - ! empty( $data['object'] ) &&
58 - \is_array( $data['object'] ) &&
59 - ! empty( $data['object']['actor'] )
60 - ) {
61 - $recipient_items[] = object_to_uri( $data['object']['actor'] );
62 - }
63 -
64 - return \array_unique( \array_filter( $recipient_items ) );
54 + return \array_unique( $recipient_items );
65 55 }
66 56
67 57 /**
68 58 * Extract recipient URLs from a specific property of an Activity object.
@@ -102,21 +92,21 @@
102 92 * ACTIVITYPUB_CONTENT_VISIBILITY_PRIVATE.
103 93 */
104 94 function get_activity_visibility( $activity ) {
105 95 // Set default visibility for specific activity types.
106 - if ( ! empty( $activity['type'] ) && \in_array( $activity['type'], array( 'Accept', 'Delete', 'Follow', 'Reject', 'Undo' ), true ) ) {
96 + if ( ! empty( $activity['type'] ) && in_array( $activity['type'], array( 'Accept', 'Delete', 'Follow', 'Reject', 'Undo' ), true ) ) {
107 97 return ACTIVITYPUB_CONTENT_VISIBILITY_PRIVATE;
108 98 }
109 99
110 100 // Check 'to' field for public visibility.
111 101 $to = extract_recipients_from_activity_property( 'to', $activity );
112 - if ( ! empty( \array_intersect( $to, ACTIVITYPUB_PUBLIC_AUDIENCE_IDENTIFIERS ) ) ) {
102 + if ( ! empty( array_intersect( $to, ACTIVITYPUB_PUBLIC_AUDIENCE_IDENTIFIERS ) ) ) {
113 103 return ACTIVITYPUB_CONTENT_VISIBILITY_PUBLIC;
114 104 }
115 105
116 106 // Check 'cc' field for quiet public visibility.
117 107 $cc = extract_recipients_from_activity_property( 'cc', $activity );
118 - if ( ! empty( \array_intersect( $cc, ACTIVITYPUB_PUBLIC_AUDIENCE_IDENTIFIERS ) ) ) {
108 + if ( ! empty( array_intersect( $cc, ACTIVITYPUB_PUBLIC_AUDIENCE_IDENTIFIERS ) ) ) {
119 109 return ACTIVITYPUB_CONTENT_VISIBILITY_QUIET_PUBLIC;
120 110 }
121 111
122 112 return ACTIVITYPUB_CONTENT_VISIBILITY_PRIVATE;
@@ -142,9 +132,9 @@
142 132 if ( empty( $recipients ) ) {
143 133 return false;
144 134 }
145 135
146 - return ! empty( \array_intersect( $recipients, ACTIVITYPUB_PUBLIC_AUDIENCE_IDENTIFIERS ) );
136 + return ! empty( array_intersect( $recipients, ACTIVITYPUB_PUBLIC_AUDIENCE_IDENTIFIERS ) );
147 137 }
148 138
149 139 /**
150 140 * Check if passed Activity is a reply.
@@ -181,13 +171,13 @@
181 171 * @return string|null The URI of the ActivityPub object.
182 172 */
183 173 function object_to_uri( $data ) {
184 174 // Check whether it is already simple.
185 - if ( ! $data || \is_string( $data ) ) {
175 + if ( ! $data || is_string( $data ) ) {
186 176 return $data;
187 177 }
188 178
189 - if ( \is_object( $data ) ) {
179 + if ( is_object( $data ) ) {
190 180 $data = $data->to_array();
191 181 }
192 182
193 183 /*
@@ -193,14 +183,14 @@
193 183 /*
194 184 * Check if it is a list, then take first item.
195 185 * This plugin does not support collections.
196 186 */
197 - if ( \array_is_list( $data ) ) {
187 + if ( array_is_list( $data ) ) {
198 188 $data = $data[0];
199 189 }
200 190
201 191 // Check if it is simplified now.
202 - if ( \is_string( $data ) ) {
192 + if ( is_string( $data ) ) {
203 193 return $data;
204 194 }
205 195
206 196 $type = 'Object';
@@ -221,22 +211,10 @@
221 211 case 'Mention': // See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-mention.
222 212 $data = $data['href'];
223 213 break;
224 214
225 - case 'FeaturedItem': // See https://github.com/mastodon/featured_collections/pull/1.
226 - $data = object_to_uri( $data['featuredObject'] ?? null );
227 - break;
228 -
229 215 default:
230 - if ( isset( $data['id'] ) ) {
231 - $data = $data['id'];
232 - } elseif ( isset( $data['url'] ) ) {
233 - $data = object_to_uri( $data['url'] );
234 - } elseif ( isset( $data['href'] ) ) {
235 - $data = $data['href'];
236 - } else {
237 - $data = null;
238 - }
216 + $data = $data['id'];
239 217 break;
240 218 }
241 219
242 220 return $data;
@@ -242,83 +220,8 @@
242 220 return $data;
243 221 }
244 222
245 223 /**
246 - * Check whether two references point at the same actor.
247 - *
248 - * Both values are resolved to their canonical URI via object_to_uri() before
249 - * comparison. Empty references never match, so a missing actor can never be
250 - * mistaken for a match.
251 - *
252 - * @param array|object|string $a The first actor reference.
253 - * @param array|object|string $b The second actor reference.
254 - *
255 - * @return bool True when both resolve to the same non-empty URI.
256 - */
257 -function is_same_actor( $a, $b ) {
258 - $a = object_to_uri( $a );
259 - $b = object_to_uri( $b );
260 -
261 - return ! empty( $a ) && ! empty( $b ) && $a === $b;
262 -}
263 -
264 -/**
265 - * Check whether two references live on the same host.
266 - *
267 - * Both values are resolved to their canonical URI via object_to_uri(), then
268 - * their hosts are compared case-insensitively. Empty references, or references
269 - * without a host, never match.
270 - *
271 - * @param array|object|string $a The first reference.
272 - * @param array|object|string $b The second reference.
273 - *
274 - * @return bool True when both resolve to a URI on the same host.
275 - */
276 -function is_same_host( $a, $b ) {
277 - $host_a = \wp_parse_url( (string) object_to_uri( $a ), PHP_URL_HOST );
278 - $host_b = \wp_parse_url( (string) object_to_uri( $b ), PHP_URL_HOST );
279 -
280 - return ! empty( $host_a ) && ! empty( $host_b ) && \strtolower( $host_a ) === \strtolower( $host_b );
281 -}
282 -
283 -/**
284 - * Whether an object is served under its own canonical id.
285 - *
286 - * An object is only trustworthy to cache when its own `id` is the URL it was
287 - * actually served from: otherwise one host could serve a document — and its
288 - * public key — under another host's id. Reads the raw `id` attribute only
289 - * (never the `url`/`href` fallback that object_to_uri() applies), because the
290 - * cache is keyed on `id`, so "is this canonical?" must ask the same field the
291 - * write uses. The comparison ignores the URL fragment and a trailing slash;
292 - * everything else (scheme, host, port, path, query) must match exactly.
293 - * Host-level equality is deliberately NOT enough — any different id on the same
294 - * host is still a distinct cache entry that a document served elsewhere must not write.
295 - *
296 - * @param array|string $item The fetched object, or its id.
297 - * @param string $url The URL the object was served from.
298 - *
299 - * @return bool True when the object's id is the canonical URL it was served from.
300 - */
301 -function id_matches_url( $item, $url ) {
302 - if ( \is_array( $item ) ) {
303 - $id = isset( $item['id'] ) && \is_string( $item['id'] ) ? $item['id'] : '';
304 - } elseif ( \is_string( $item ) ) {
305 - $id = $item;
306 - } else {
307 - $id = '';
308 - }
309 -
310 - $id = \strip_fragment_from_url( $id );
311 - $url = \strip_fragment_from_url( (string) $url );
312 -
313 - if ( '' === $id || '' === $url ) {
314 - return false;
315 - }
316 -
317 - return \untrailingslashit( $id ) === \untrailingslashit( $url );
318 -}
319 -
320 -/**
321 224 * Check if an `$data` is an Activity.
322 225 *
323 226 * @see https://www.w3.org/ns/activitystreams#activities
324 227 *
@@ -331,9 +234,9 @@
331 234 * Filters the activity types.
332 235 *
333 236 * @param array $types The activity types.
334 237 */
335 - $types = \apply_filters( 'activitypub_activity_types', Activity::TYPES );
238 + $types = apply_filters( 'activitypub_activity_types', Activity::TYPES );
336 239
337 240 return _is_type_of( $data, $types );
338 241 }
339 242
@@ -371,9 +274,9 @@
371 274 * Filters the actor types.
372 275 *
373 276 * @param array $types The actor types.
374 277 */
375 - $types = \apply_filters( 'activitypub_actor_types', Actor::TYPES );
278 + $types = apply_filters( 'activitypub_actor_types', Actor::TYPES );
376 279
377 280 return _is_type_of( $data, $types );
378 281 }
379 282
@@ -391,9 +294,9 @@
391 294 * Filters the collection types.
392 295 *
393 296 * @param array $types The collection types.
394 297 */
395 - $types = \apply_filters( 'activitypub_collection_types', array( 'Collection', 'OrderedCollection', 'CollectionPage', 'OrderedCollectionPage' ) );
298 + $types = apply_filters( 'activitypub_collection_types', array( 'Collection', 'OrderedCollection', 'CollectionPage', 'OrderedCollectionPage' ) );
396 299
397 300 return _is_type_of( $data, $types );
398 301 }
399 302
@@ -405,18 +308,18 @@
405 308 *
406 309 * @return boolean True if $data is of one of the types, false otherwise.
407 310 */
408 311 function _is_type_of( $data, $types ) {
409 - if ( \is_string( $data ) ) {
410 - return \in_array( $data, $types, true );
312 + if ( is_string( $data ) ) {
313 + return in_array( $data, $types, true );
411 314 }
412 315
413 - if ( \is_array( $data ) && isset( $data['type'] ) ) {
414 - return \in_array( $data['type'], $types, true );
316 + if ( is_array( $data ) && isset( $data['type'] ) ) {
317 + return in_array( $data['type'], $types, true );
415 318 }
416 319
417 320 if ( $data instanceof Base_Object ) {
418 - return \in_array( $data->get_type(), $types, true );
321 + return in_array( $data->get_type(), $types, true );
419 322 }
420 323
421 324 return false;
422 325 }