PluginProbe
ActivityPub / 9.2.1
ActivityPub v9.2.1
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/activity/class-base-object.php +287 -289 1.2.09.2.1 View file →
@@ -2,18 +2,16 @@
2 2 /**
3 3 * Inspired by the PHP ActivityPub Library by @Landrok
4 4 *
5 5 * @link https://github.com/landrok/activitypub
6 + *
7 + * @package Activitypub
6 8 */
7 9
8 10 namespace Activitypub\Activity;
9 11
10 -use WP_Error;
11 -use ReflectionClass;
12 +use Activitypub\Activity\Extended_Object\Place;
12 13
13 -use function Activitypub\camel_to_snake_case;
14 -use function Activitypub\snake_to_camel_case;
15 -
16 14 /**
17 15 * Base_Object is an implementation of one of the
18 16 * Activity Streams Core Types.
19 17 *
@@ -23,20 +21,178 @@
23 21 * Note: Object is a reserved keyword in PHP. It has been suffixed with
24 22 * 'Base_' for this reason.
25 23 *
26 24 * @see https://www.w3.org/TR/activitystreams-core/#object
25 + *
26 + * @method array|string|null get_attachment() Gets the attachment property of the object.
27 + * @method array|string|null get_attributed_to() Gets the entity attributed as the original author.
28 + * @method string|null get_audience() Gets the total population of entities for which the object can be considered relevant.
29 + * @method string[]|string|null get_bcc() Gets the private secondary audience of the object.
30 + * @method string[]|string|null get_bto() Gets the private primary audience of the object.
31 + * @method string[]|string|null get_cc() Gets the secondary recipients of the object.
32 + * @method string|null get_content() Gets the content property of the object.
33 + * @method string[]|null get_content_map() Gets the content map property of the object.
34 + * @method string|null get_context() Gets the context within which the object exists.
35 + * @method array|null get_dcterms() Gets the Dublin Core terms property of the object.
36 + * @method string|null get_duration() Gets the duration property of time-bound resources.
37 + * @method string|null get_end_time() Gets the date and time describing the ending time of the object.
38 + * @method string|null get_generator() Gets the entity that generated the object.
39 + * @method string[]|null get_icon() Gets the icon property of the object.
40 + * @method string|null get_id() Gets the object's unique global identifier.
41 + * @method string[]|null get_image() Gets the image property of the object.
42 + * @method string[]|string|null get_in_reply_to() Gets the objects this object is in reply to.
43 + * @method array|null get_interaction_policy() Gets the interaction policy property of the object.
44 + * @method array|null get_likes() Gets the collection of likes for this object.
45 + * @method array|string|null|Place get_location() Gets the physical or logical locations associated with the object.
46 + * @method string|null get_media_type() Gets the MIME media type of the content property.
47 + * @method string|null get_name() Gets the natural language name of the object.
48 + * @method string[]|null get_name_map() Gets the name map property of the object.
49 + * @method string|null get_preview() Gets the entity that provides a preview of this object.
50 + * @method string|null get_published() Gets the date and time the object was published in ISO 8601 format.
51 + * @method string|null get_quote() Gets the quote property of the object (FEP-044f).
52 + * @method string|null get_quote_url() Gets the quoteUrl property of the object.
53 + * @method string|null get_quote_uri() Gets the quoteUri property of the object.
54 + * @method string|null get__misskey_quote() Gets the _misskey_quote property of the object.
55 + * @method string|array|null get_replies() Gets the collection of responses to this object.
56 + * @method bool|null get_sensitive() Gets the sensitive property of the object.
57 + * @method array|null get_shares() Gets the collection of shares for this object.
58 + * @method array|null get_source() Gets the source property indicating content markup derivation.
59 + * @method string|null get_start_time() Gets the date and time describing the starting time of the object.
60 + * @method string|null get_summary() Gets the natural language summary of the object.
61 + * @method string[]|null get_summary_map() Gets the summary map property of the object.
62 + * @method array[]|null get_tag() Gets the tag property of the object.
63 + * @method string[]|string|null get_to() Gets the primary recipients of the object.
64 + * @method string get_type() Gets the type of the object.
65 + * @method string|null get_updated() Gets the date and time the object was updated in ISO 8601 format.
66 + * @method string|null get_url() Gets the URL of the object.
67 + * @method string|null get_former_type() Gets the former type of a Tombstone object.
68 + * @method string|null get_deleted() Gets the date and time the object was deleted in ISO 8601 format.
69 + *
70 + * @method string|string[] add_cc( string|array $cc ) Adds one or more entities to the secondary audience of the object.
71 + * @method string|string[] add_to( string|array $to ) Adds one or more entities to the primary audience of the object.
72 + *
73 + * @method Base_Object set_attachment( array $attachment ) Sets the attachment property of the object.
74 + * @method Base_Object set_attributed_to( string $attributed_to ) Sets the entity attributed as the original author.
75 + * @method Base_Object set_audience( string $audience ) Sets the total population of entities for which the object can be considered relevant.
76 + * @method Base_Object set_bcc( array|string $bcc ) Sets the private secondary audience of the object.
77 + * @method Base_Object set_bto( array|string $bto ) Sets the private primary audience of the object.
78 + * @method Base_Object set_cc( array|string $cc ) Sets the secondary recipients of the object.
79 + * @method Base_Object set_content( string $content ) Sets the content property of the object.
80 + * @method Base_Object set_content_map( array $content_map ) Sets the content property of the object.
81 + * @method Base_Object set_context( string $context ) Sets the context within which the object exists.
82 + * @method Base_Object set_dcterms( array $dcterms ) Sets the Dublin Core terms property of the object.
83 + * @method Base_Object set_duration( string $duration ) Sets the duration property of time-bound resources.
84 + * @method Base_Object set_end_time( string $end_time ) Sets the date and time describing the ending time of the object.
85 + * @method Base_Object set_generator( string $generator ) Sets the entity that generated the object.
86 + * @method Base_Object set_icon( array $icon ) Sets the icon property of the object.
87 + * @method Base_Object set_id( string $id ) Sets the object's unique global identifier.
88 + * @method Base_Object set_image( array $image ) Sets the image property of the object.
89 + * @method Base_Object set_in_reply_to( string|string[] $in_reply_to ) Sets the is in reply to property of the object.
90 + * @method Base_Object set_interaction_policy( array|null $policy ) Sets the interaction policy property of the object.
91 + * @method Base_Object set_likes( array $likes ) Sets the collection of likes for this object.
92 + * @method Base_Object set_location( array|string|Place $location ) Sets the physical or logical locations associated with the object.
93 + * @method Base_Object set_media_type( string $media_type ) Sets the MIME media type of the content property.
94 + * @method Base_Object set_name( string $name ) Sets the natural language name of the object.
95 + * @method Base_Object set_name_map( array|null $name_map ) Sets the name map property of the object.
96 + * @method Base_Object set_preview( string $preview ) Sets the entity that provides a preview of this object.
97 + * @method Base_Object set_published( string|null $published ) Sets the date and time the object was published in ISO 8601 format.
98 + * @method Base_Object set_quote( string $quote ) Sets the quote property of the object (FEP-044f).
99 + * @method Base_Object set_quote_url( string $quote_url ) Sets the quoteUrl property of the object.
100 + * @method Base_Object set_quote_uri( string $quote_uri ) Sets the quoteUri property of the object.
101 + * @method Base_Object set__misskey_quote( mixed $misskey_quote ) Sets the _misskey_quote property of the object.
102 + * @method Base_Object set_replies( string|array $replies ) Sets the collection of responses to this object.
103 + * @method Base_Object set_sensitive( bool|null $sensitive ) Sets the sensitive property of the object.
104 + * @method Base_Object set_shares( array $shares ) Sets the collection of shares for this object.
105 + * @method Base_Object set_source( array $source ) Sets the source property indicating content markup derivation.
106 + * @method Base_Object set_start_time( string $start_time ) Sets the date and time describing the starting time of the object.
107 + * @method Base_Object set_summary( string $summary ) Sets the natural language summary of the object.
108 + * @method Base_Object set_summary_map( array|null $summary_map ) Sets the summary property of the object.
109 + * @method Base_Object set_tag( array|null $tag ) Sets the tag property of the object.
110 + * @method Base_Object set_to( string|string[] $to ) Sets the primary recipients of the object.
111 + * @method Base_Object set_type( string $type ) Sets the type of the object.
112 + * @method Base_Object set_updated( string $updated ) Sets the date and time the object was updated in ISO 8601 format.
113 + * @method Base_Object set_url( string $url ) Sets the URL of the object.
114 + * @method Base_Object set_former_type( string $former_type ) Sets the former type of a Tombstone object.
115 + * @method Base_Object set_deleted( string $deleted ) Sets the date and time the object was deleted in ISO 8601 format.
27 116 */
28 -class Base_Object {
117 +class Base_Object extends Generic_Object {
29 118 /**
30 - * The object's unique global identifier
119 + * The JSON-LD context for the object.
31 120 *
32 - * @see https://www.w3.org/TR/activitypub/#obj-id
121 + * @var array
122 + */
123 + const JSON_LD_CONTEXT = array(
124 + 'https://www.w3.org/ns/activitystreams',
125 + array(
126 + 'Hashtag' => 'as:Hashtag',
127 + 'sensitive' => 'as:sensitive',
128 + 'dcterms' => 'http://purl.org/dc/terms/',
129 + 'gts' => 'https://gotosocial.org/ns#',
130 + 'schema' => 'http://schema.org/',
131 + 'exifData' => 'schema:exifData',
132 + 'PropertyValue' => 'schema:PropertyValue',
133 + 'interactionPolicy' => array(
134 + '@id' => 'gts:interactionPolicy',
135 + '@type' => '@id',
136 + ),
137 + 'canQuote' => array(
138 + '@id' => 'gts:canQuote',
139 + '@type' => '@id',
140 + ),
141 + 'canReply' => array(
142 + '@id' => 'gts:canReply',
143 + '@type' => '@id',
144 + ),
145 + 'canLike' => array(
146 + '@id' => 'gts:canLike',
147 + '@type' => '@id',
148 + ),
149 + 'canAnnounce' => array(
150 + '@id' => 'gts:canAnnounce',
151 + '@type' => '@id',
152 + ),
153 + 'automaticApproval' => array(
154 + '@id' => 'gts:automaticApproval',
155 + '@type' => '@id',
156 + ),
157 + 'manualApproval' => array(
158 + '@id' => 'gts:manualApproval',
159 + '@type' => '@id',
160 + ),
161 + 'always' => array(
162 + '@id' => 'gts:always',
163 + '@type' => '@id',
164 + ),
165 + 'toot' => 'http://joinmastodon.org/ns#',
166 + 'blurhash' => 'toot:blurhash',
167 + ),
168 + );
169 +
170 + /**
171 + * The default types for Objects.
33 172 *
34 - * @var string
173 + * @see https://www.w3.org/TR/activitystreams-vocabulary/#object-types
174 + *
175 + * @var array
35 176 */
36 - protected $id;
177 + const TYPES = array(
178 + 'Article',
179 + 'Audio',
180 + 'Document',
181 + 'Event',
182 + 'Image',
183 + 'Note',
184 + 'Page',
185 + 'Place',
186 + 'Profile',
187 + 'Relationship',
188 + 'Tombstone',
189 + 'Video',
190 + );
37 191
38 192 /**
193 + * The type of the object.
194 + *
39 195 * @var string
40 196 */
41 197 protected $type = 'Object';
42 198
@@ -47,14 +203,9 @@
47 203 * similar to attachments in email.
48 204 *
49 205 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-attachment
50 206 *
51 - * @var string
52 - * | ObjectType
53 - * | Link
54 - * | array<ObjectType>
55 - * | array<Link>
56 - * | null
207 + * @var string|null
57 208 */
58 209 protected $attachment;
59 210
60 211 /**
@@ -63,29 +214,19 @@
63 214 * object might be attributed to the completion of another activity.
64 215 *
65 216 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-attributedto
66 217 *
67 - * @var string
68 - * | ObjectType
69 - * | Link
70 - * | array<ObjectType>
71 - * | array<Link>
72 - * | null
218 + * @var string|null
73 219 */
74 220 protected $attributed_to;
75 221
76 222 /**
77 223 * One or more entities that represent the total population of
78 - * entities for which the object can considered to be relevant.
224 + * entities for which the object can be considered to be relevant.
79 225 *
80 226 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-audience
81 227 *
82 - * @var string
83 - * | ObjectType
84 - * | Link
85 - * | array<ObjectType>
86 - * | array<Link>
87 - * | null
228 + * @var string|null
88 229 */
89 230 protected $audience;
90 231
91 232 /**
@@ -113,12 +254,9 @@
113 254 * project or event.
114 255 *
115 256 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-context
116 257 *
117 - * @var string
118 - * | ObjectType
119 - * | Link
120 - * | null
258 + * @var string|null
121 259 */
122 260 protected $context;
123 261
124 262 /**
@@ -131,8 +269,27 @@
131 269 */
132 270 protected $content_map;
133 271
134 272 /**
273 + * The date and time at which the object was deleted.
274 + *
275 + * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-deleted
276 + *
277 + * @var string|null
278 + */
279 + protected $deleted;
280 +
281 + /**
282 + * The former type of the object. Used in Tombstone objects to
283 + * indicate the type of the object prior to deletion.
284 + *
285 + * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-formertype
286 + *
287 + * @var string|null
288 + */
289 + protected $former_type;
290 +
291 + /**
135 292 * A simple, human-readable, plain-text name for the object.
136 293 * HTML markup MUST NOT be included.
137 294 *
138 295 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-name
@@ -177,14 +334,9 @@
177 334 * at a small size.
178 335 *
179 336 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-icon
180 337 *
181 - * @var string
182 - * | Image
183 - * | Link
184 - * | array<Image>
185 - * | array<Link>
186 - * | null
338 + * @var string|array|null
187 339 */
188 340 protected $icon;
189 341
190 342 /**
@@ -193,14 +345,9 @@
193 345 * or display size limitations assumed.
194 346 *
195 347 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-image-term
196 348 *
197 - * @var string
198 - * | Image
199 - * | Link
200 - * | array<Image>
201 - * | array<Link>
202 - * | null
349 + * @var string|array|null
203 350 */
204 351 protected $image;
205 352
206 353 /**
@@ -208,14 +355,9 @@
208 355 * response.
209 356 *
210 357 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-inreplyto
211 358 *
212 - * @var string
213 - * | ObjectType
214 - * | Link
215 - * | array<ObjectType>
216 - * | array<Link>
217 - * | null
359 + * @var string|null
218 360 */
219 361 protected $in_reply_to;
220 362
221 363 /**
@@ -223,14 +365,9 @@
223 365 * object.
224 366 *
225 367 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-location
226 368 *
227 - * @var string
228 - * | ObjectType
229 - * | Link
230 - * | array<ObjectType>
231 - * | array<Link>
232 - * | null
369 + * @var string|null|Place
233 370 */
234 371 protected $location;
235 372
236 373 /**
@@ -237,12 +374,9 @@
237 374 * An entity that provides a preview of this object.
238 375 *
239 376 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-preview
240 377 *
241 - * @var string
242 - * | ObjectType
243 - * | Link
244 - * | null
378 + * @var string|null
245 379 */
246 380 protected $preview;
247 381
248 382 /**
@@ -254,21 +388,8 @@
254 388 */
255 389 protected $published;
256 390
257 391 /**
258 - * A Collection containing objects considered to be responses to
259 - * this object.
260 - *
261 - * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-replies
262 - *
263 - * @var string
264 - * | Collection
265 - * | Link
266 - * | null
267 - */
268 - protected $replies;
269 -
270 - /**
271 392 * The date and time describing the actual or expected starting time
272 393 * of the object.
273 394 * When used with an Activity object, for instance, the startTime
274 395 * property specifies the moment the activity began
@@ -285,12 +406,9 @@
285 406 * Multiple language tagged summaries MAY be provided.
286 407 *
287 408 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-summary
288 409 *
289 - * @var string
290 - * | ObjectType
291 - * | Link
292 - * | null
410 + * @var string|null
293 411 */
294 412 protected $summary;
295 413
296 414 /**
@@ -298,9 +416,9 @@
298 416 * values.
299 417 *
300 418 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-summary
301 419 *
302 - * @var array<string>|null
420 + * @var string[]|null
303 421 */
304 422 protected $summary_map;
305 423
306 424 /**
@@ -311,14 +429,9 @@
311 429 * associated by reference.
312 430 *
313 431 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-tag
314 432 *
315 - * @var string
316 - * | ObjectType
317 - * | Link
318 - * | array<ObjectType>
319 - * | array<Link>
320 - * | null
433 + * @var string|null
321 434 */
322 435 protected $tag;
323 436
324 437 /**
@@ -332,13 +445,9 @@
332 445
333 446 /**
334 447 * One or more links to representations of the object.
335 448 *
336 - * @var string
337 - * | array<string>
338 - * | Link
339 - * | array<Link>
340 - * | null
449 + * @var string|null
341 450 */
342 451 protected $url;
343 452
344 453 /**
@@ -346,14 +455,9 @@
346 455 * of an Object
347 456 *
348 457 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-to
349 458 *
350 - * @var string
351 - * | ObjectType
352 - * | Link
353 - * | array<ObjectType>
354 - * | array<Link>
355 - * | null
459 + * @var string|array|null
356 460 */
357 461 protected $to;
358 462
359 463 /**
@@ -361,14 +465,9 @@
361 465 * Object.
362 466 *
363 467 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-bto
364 468 *
365 - * @var string
366 - * | ObjectType
367 - * | Link
368 - * | array<ObjectType>
369 - * | array<Link>
370 - * | null
469 + * @var string|array|null
371 470 */
372 471 protected $bto;
373 472
374 473 /**
@@ -376,14 +475,9 @@
376 475 * Object.
377 476 *
378 477 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-cc
379 478 *
380 - * @var string
381 - * | ObjectType
382 - * | Link
383 - * | array<ObjectType>
384 - * | array<Link>
385 - * | null
479 + * @var string|array|null
386 480 */
387 481 protected $cc;
388 482
389 483 /**
@@ -391,14 +485,9 @@
391 485 * audience of this Object.
392 486 *
393 487 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-bcc
394 488 *
395 - * @var string
396 - * | ObjectType
397 - * | Link
398 - * | array<ObjectType>
399 - * | array<Link>
400 - * | null
489 + * @var string|array|null
401 490 */
402 491 protected $bcc;
403 492
404 493 /**
@@ -413,11 +502,11 @@
413 502 protected $media_type;
414 503
415 504 /**
416 505 * When the object describes a time-bound resource, such as an audio
417 - * or video, a meeting, etc, the duration property indicates the
506 + * or video, a meeting, etc., the duration property indicates the
418 507 * object's approximate duration.
419 - * The value MUST be expressed as an xsd:duration as defined by
508 + * The value MUST be expressed as a xsd:duration as defined by
420 509 * xmlschema11-2, section 3.3.6 (e.g. a period of 5 seconds is
421 510 * represented as "PT5S").
422 511 *
423 512 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration
@@ -432,247 +521,156 @@
432 521 * future editing by clients.
433 522 *
434 523 * @see https://www.w3.org/TR/activitypub/#source-property
435 524 *
436 - * @var ObjectType
525 + * @var array|null
437 526 */
438 527 protected $source;
439 528
440 529 /**
441 - * Magic function to implement getter and setter
530 + * A Collection containing objects considered to be responses to
531 + * this object.
442 532 *
443 - * @param string $method The method name.
444 - * @param string $params The method params.
533 + * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-replies
445 534 *
446 - * @return void
535 + * @var string|array|null
447 536 */
448 - public function __call( $method, $params ) {
449 - $var = \strtolower( \substr( $method, 4 ) );
537 + protected $replies;
450 538
451 - if ( \strncasecmp( $method, 'get', 3 ) === 0 ) {
452 - if ( ! $this->has( $var ) ) {
453 - return new WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
454 - }
455 -
456 - return $this->$var;
457 - }
458 -
459 - if ( \strncasecmp( $method, 'set', 3 ) === 0 ) {
460 - $this->set( $var, $params[0] );
461 - }
462 -
463 - if ( \strncasecmp( $method, 'add', 3 ) === 0 ) {
464 - $this->add( $var, $params[0] );
465 - }
466 - }
467 -
468 539 /**
469 - * Magic function, to transform the object to string.
540 + * A Collection containing objects considered to be likes for
541 + * this object.
470 542 *
471 - * @return string The object id.
543 + * @see https://www.w3.org/TR/activitypub/#likes
544 + *
545 + * @var array|null
472 546 */
473 - public function __toString() {
474 - return $this->to_string();
475 - }
547 + protected $likes;
476 548
477 549 /**
478 - * Function to transform the object to string.
550 + * A Collection containing objects considered to be shares for
551 + * this object.
479 552 *
480 - * @return string The object id.
553 + * @see https://www.w3.org/TR/activitypub/#shares
554 + *
555 + * @var array|null
481 556 */
482 - public function to_string() {
483 - return $this->get_id();
484 - }
557 + protected $shares;
485 558
486 559 /**
487 - * Generic getter.
560 + * Used to mark an object as containing sensitive content.
561 + * Mastodon displays a content warning, requiring users to click
562 + * through to view the content.
488 563 *
489 - * @param string $key The key to get.
564 + * @see https://docs.joinmastodon.org/spec/activitypub/#sensitive
490 565 *
491 - * @return mixed The value.
566 + * @var boolean|null
492 567 */
493 - public function get( $key ) {
494 - if ( ! $this->has( $key ) ) {
495 - return new WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
496 - }
568 + protected $sensitive;
497 569
498 - return call_user_func( array( $this, 'get_' . $key ) );
499 - }
500 -
501 570 /**
502 - * Check if the object has a key
571 + * The dcterms namespace.
503 572 *
504 - * @param string $key The key to check.
573 + * @see https://codeberg.org/fediverse/fep/src/branch/main/fep/b2b8/fep-b2b8.md#sensitive
574 + * @see https://www.dublincore.org/specifications/dublin-core/dcmi-terms/
505 575 *
506 - * @return boolean True if the object has the key.
576 + * @var array|null
507 577 */
508 - public function has( $key ) {
509 - return property_exists( $this, $key );
510 - }
578 + protected $dcterms;
511 579
512 580 /**
513 - * Generic setter.
581 + * Interaction policy is an attempt to limit the harmful effects of unwanted replies and
582 + * other interactions on a user's posts (e.g., "reply guys").
514 583 *
515 - * @param string $key The key to set.
516 - * @param string $value The value to set.
584 + * It is also used by Mastodon to limit the ability to quote posts.
517 585 *
518 - * @return mixed The value.
586 + * @see https://docs.gotosocial.org/en/latest/federation/interaction_policy/
587 + * @see https://blog.joinmastodon.org/2025/09/introducing-quote-posts/
588 + *
589 + * @var array|null
519 590 */
520 - public function set( $key, $value ) {
521 - if ( ! $this->has( $key ) ) {
522 - return new WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
523 - }
591 + protected $interaction_policy;
524 592
525 - $this->$key = $value;
526 -
527 - return $this->$key;
528 - }
529 -
530 593 /**
531 - * Generic adder.
594 + * Fediverse Enhancement Proposal 044f: Quote Property
532 595 *
533 - * @param string $key The key to set.
534 - * @param mixed $value The value to add.
596 + * @see https://codeberg.org/fediverse/fep/src/branch/main/fep/044f/fep-044f.md
597 + * @see https://w3id.org/fep/044f#quote
535 598 *
536 - * @return mixed The value.
599 + * @var string|null
537 600 */
538 - public function add( $key, $value ) {
539 - if ( ! $this->has( $key ) ) {
540 - return new WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
541 - }
601 + protected $quote;
542 602
543 - if ( ! isset( $this->$key ) ) {
544 - $this->$key = array();
545 - }
546 -
547 - $attributes = $this->$key;
548 - $attributes[] = $value;
549 -
550 - $this->$key = $attributes;
551 -
552 - return $this->$key;
553 - }
554 -
555 603 /**
556 - * Convert JSON input to an array.
604 + * ActivityStreams quoteUrl property.
557 605 *
558 - * @return string The JSON string.
606 + * @see https://www.w3.org/ns/activitystreams#quoteUrl
559 607 *
560 - * @return \Activitypub\Activity\Base_Object An Object built from the JSON string.
608 + * @var string|null
561 609 */
562 - public static function init_from_json( $json ) {
563 - $array = \json_decode( $json, true );
610 + protected $quote_url;
564 611
565 - if ( ! is_array( $array ) ) {
566 - $array = array();
567 - }
568 -
569 - return self::init_from_array( $array );
570 - }
571 -
572 612 /**
573 - * Convert JSON input to an array.
613 + * Fedibird-specific quoteUri property.
574 614 *
575 - * @return string The object array.
615 + * @see https://fedibird.com/ns#quoteUri
576 616 *
577 - * @return \Activitypub\Activity\Base_Object An Object built from the JSON string.
617 + * @var string|null
578 618 */
579 - public static function init_from_array( $array ) {
580 - if ( ! is_array( $array ) ) {
581 - return new WP_Error( 'invalid_array', __( 'Invalid array', 'activitypub' ), array( 'status' => 404 ) );
582 - }
619 + protected $quote_uri;
583 620
584 - $object = new static();
585 -
586 - foreach ( $array as $key => $value ) {
587 - $key = camel_to_snake_case( $key );
588 - $object->set( $key, $value );
589 - }
590 -
591 - return $object;
592 - }
593 -
594 621 /**
595 - * Convert JSON input to an array and pre-fill the object.
622 + * Misskey-specific quote property.
596 623 *
597 - * @param string $json The JSON string.
624 + * @see https://misskey-hub.net/ns/#_misskey_quote
625 + *
626 + * @var string|null
598 627 */
599 - public function from_json( $json ) {
600 - $array = \json_decode( $json, true );
628 + protected $_misskey_quote; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
601 629
602 - $this->from_array( $array );
603 - }
604 -
605 630 /**
606 - * Convert JSON input to an array and pre-fill the object.
631 + * Generic getter.
607 632 *
608 - * @param array $array The array.
633 + * @param string $key The key to get.
634 + *
635 + * @return mixed The value.
609 636 */
610 - public function from_array( $array ) {
611 - foreach ( $array as $key => $value ) {
612 - if ( $value ) {
613 - $key = camel_to_snake_case( $key );
614 - $this->set( $key, $value );
615 - }
637 + public function get( $key ) {
638 + if ( ! $this->has( $key ) ) {
639 + return new \WP_Error( 'invalid_key', \__( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
616 640 }
641 +
642 + return parent::get( $key );
617 643 }
618 644
619 645 /**
620 - * Convert Object to an array.
646 + * Generic setter.
621 647 *
622 - * It tries to get the object attributes if they exist
623 - * and falls back to the getters. Empty values are ignored.
648 + * @param string $key The key to set.
649 + * @param string $value The value to set.
624 650 *
625 - * @return array An array built from the Object.
651 + * @return mixed The value.
626 652 */
627 - public function to_array() {
628 - $array = array();
629 - $vars = get_object_vars( $this );
630 -
631 - foreach ( $vars as $key => $value ) {
632 - // ignotre all _prefixed keys.
633 - if ( '_' === substr( $key, 0, 1 ) ) {
634 - continue;
635 - }
636 -
637 - // if value is empty, try to get it from a getter.
638 - if ( ! $value ) {
639 - $value = call_user_func( array( $this, 'get_' . $key ) );
640 - }
641 -
642 - if ( is_object( $value ) ) {
643 - $value = $value->to_array();
644 - }
645 -
646 - // if value is still empty, ignore it for the array and continue.
647 - if ( isset( $value ) ) {
648 - $array[ snake_to_camel_case( $key ) ] = $value;
649 - }
653 + public function set( $key, $value ) {
654 + if ( ! $this->has( $key ) ) {
655 + return new \WP_Error( 'invalid_key', \__( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
650 656 }
651 657
652 - // replace 'context' key with '@context' and move it to the top.
653 - if ( array_key_exists( 'context', $array ) ) {
654 - $context = $array['context'];
655 - unset( $array['context'] );
656 - $array = array_merge( array( '@context' => $context ), $array );
657 - }
658 -
659 - $class = new ReflectionClass( $this );
660 - $class = strtolower( $class->getShortName() );
661 -
662 - $array = \apply_filters( 'activitypub_activity_object_array', $array, $class, $this->id, $this );
663 - $array = \apply_filters( "activitypub_activity_{$class}_object_array", $array, $this->id, $this );
664 -
665 - return $array;
658 + return parent::set( $key, $value );
666 659 }
667 660
668 661 /**
669 - * Convert Object to JSON.
662 + * Generic adder.
670 663 *
671 - * @return string The JSON string.
664 + * @param string $key The key to set.
665 + * @param mixed $value The value to add.
666 + *
667 + * @return mixed The value.
672 668 */
673 - public function to_json() {
674 - $array = $this->to_array();
669 + public function add( $key, $value ) {
670 + if ( ! $this->has( $key ) ) {
671 + return new \WP_Error( 'invalid_key', \__( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
672 + }
675 673
676 - return \wp_json_encode( $array, \JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_QUOT );
674 + return parent::add( $key, $value );
677 675 }
678 676 }