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
activitypub / includes / activity / class-base-object.php

class-base-object.php in ActivityPub 8.0.2, at includes/activity/class-base-object.php

672 lines 23.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Inspired by the PHP ActivityPub Library by @Landrok
4 *
5 * @link https://github.com/landrok/activitypub
6 *
7 * @package Activitypub
8 */
9
10 namespace Activitypub\Activity;
11
12 use Activitypub\Activity\Extended_Object\Place;
13
14 /**
15 * Base_Object is an implementation of one of the
16 * Activity Streams Core Types.
17 *
18 * The Object is the primary base type for the Activity Streams
19 * vocabulary.
20 *
21 * Note: Object is a reserved keyword in PHP. It has been suffixed with
22 * 'Base_' for this reason.
23 *
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.
116 */
117 class Base_Object extends Generic_Object {
118 /**
119 * The JSON-LD context for the object.
120 *
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 'interactionPolicy' => array(
131 '@id' => 'gts:interactionPolicy',
132 '@type' => '@id',
133 ),
134 'canQuote' => array(
135 '@id' => 'gts:canQuote',
136 '@type' => '@id',
137 ),
138 'canReply' => array(
139 '@id' => 'gts:canReply',
140 '@type' => '@id',
141 ),
142 'canLike' => array(
143 '@id' => 'gts:canLike',
144 '@type' => '@id',
145 ),
146 'canAnnounce' => array(
147 '@id' => 'gts:canAnnounce',
148 '@type' => '@id',
149 ),
150 'automaticApproval' => array(
151 '@id' => 'gts:automaticApproval',
152 '@type' => '@id',
153 ),
154 'manualApproval' => array(
155 '@id' => 'gts:manualApproval',
156 '@type' => '@id',
157 ),
158 'always' => array(
159 '@id' => 'gts:always',
160 '@type' => '@id',
161 ),
162 ),
163 );
164
165 /**
166 * The default types for Objects.
167 *
168 * @see https://www.w3.org/TR/activitystreams-vocabulary/#object-types
169 *
170 * @var array
171 */
172 const TYPES = array(
173 'Article',
174 'Audio',
175 'Document',
176 'Event',
177 'Image',
178 'Note',
179 'Page',
180 'Place',
181 'Profile',
182 'Relationship',
183 'Tombstone',
184 'Video',
185 );
186
187 /**
188 * The type of the object.
189 *
190 * @var string
191 */
192 protected $type = 'Object';
193
194 /**
195 * A resource attached or related to an object that potentially
196 * requires special handling.
197 * The intent is to provide a model that is at least semantically
198 * similar to attachments in email.
199 *
200 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-attachment
201 *
202 * @var string|null
203 */
204 protected $attachment;
205
206 /**
207 * One or more entities to which this object is attributed.
208 * The attributed entities might not be Actors. For instance, an
209 * object might be attributed to the completion of another activity.
210 *
211 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-attributedto
212 *
213 * @var string|null
214 */
215 protected $attributed_to;
216
217 /**
218 * One or more entities that represent the total population of
219 * entities for which the object can be considered to be relevant.
220 *
221 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-audience
222 *
223 * @var string|null
224 */
225 protected $audience;
226
227 /**
228 * The content or textual representation of the Object encoded as a
229 * JSON string. By default, the value of content is HTML.
230 * The mediaType property can be used in the object to indicate a
231 * different content type.
232 *
233 * The content MAY be expressed using multiple language-tagged
234 * values.
235 *
236 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-content
237 *
238 * @var string|null
239 */
240 protected $content;
241
242 /**
243 * The context within which the object exists or an activity was
244 * performed.
245 * The notion of "context" used is intentionally vague.
246 * The intended function is to serve as a means of grouping objects
247 * and activities that share a common originating context or
248 * purpose. An example could be all activities relating to a common
249 * project or event.
250 *
251 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-context
252 *
253 * @var string|null
254 */
255 protected $context;
256
257 /**
258 * The content MAY be expressed using multiple language-tagged
259 * values.
260 *
261 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-content
262 *
263 * @var array|null
264 */
265 protected $content_map;
266
267 /**
268 * The date and time at which the object was deleted.
269 *
270 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-deleted
271 *
272 * @var string|null
273 */
274 protected $deleted;
275
276 /**
277 * The former type of the object. Used in Tombstone objects to
278 * indicate the type of the object prior to deletion.
279 *
280 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-formertype
281 *
282 * @var string|null
283 */
284 protected $former_type;
285
286 /**
287 * A simple, human-readable, plain-text name for the object.
288 * HTML markup MUST NOT be included.
289 *
290 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-name
291 *
292 * @var string|null xsd:string
293 */
294 protected $name;
295
296 /**
297 * The name MAY be expressed using multiple language-tagged values.
298 *
299 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-name
300 *
301 * @var array|null rdf:langString
302 */
303 protected $name_map;
304
305 /**
306 * The date and time describing the actual or expected ending time
307 * of the object.
308 * When used with an Activity object, for instance, the endTime
309 * property specifies the moment the activity concluded or
310 * is expected to conclude.
311 *
312 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-endtime
313 *
314 * @var string|null
315 */
316 protected $end_time;
317
318 /**
319 * The entity (e.g. an application) that generated the object.
320 *
321 * @var string|null
322 */
323 protected $generator;
324
325 /**
326 * An entity that describes an icon for this object.
327 * The image should have an aspect ratio of one (horizontal)
328 * to one (vertical) and should be suitable for presentation
329 * at a small size.
330 *
331 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-icon
332 *
333 * @var string|array|null
334 */
335 protected $icon;
336
337 /**
338 * An entity that describes an image for this object.
339 * Unlike the icon property, there are no aspect ratio
340 * or display size limitations assumed.
341 *
342 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-image-term
343 *
344 * @var string|array|null
345 */
346 protected $image;
347
348 /**
349 * One or more entities for which this object is considered a
350 * response.
351 *
352 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-inreplyto
353 *
354 * @var string|null
355 */
356 protected $in_reply_to;
357
358 /**
359 * One or more physical or logical locations associated with the
360 * object.
361 *
362 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-location
363 *
364 * @var string|null|Place
365 */
366 protected $location;
367
368 /**
369 * An entity that provides a preview of this object.
370 *
371 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-preview
372 *
373 * @var string|null
374 */
375 protected $preview;
376
377 /**
378 * The date and time at which the object was published
379 *
380 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-published
381 *
382 * @var string|null xsd:dateTime
383 */
384 protected $published;
385
386 /**
387 * The date and time describing the actual or expected starting time
388 * of the object.
389 * When used with an Activity object, for instance, the startTime
390 * property specifies the moment the activity began
391 * or is scheduled to begin.
392 *
393 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-starttime
394 *
395 * @var string|null xsd:dateTime
396 */
397 protected $start_time;
398
399 /**
400 * A natural language summarization of the object encoded as HTML.
401 * Multiple language tagged summaries MAY be provided.
402 *
403 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-summary
404 *
405 * @var string|null
406 */
407 protected $summary;
408
409 /**
410 * The content MAY be expressed using multiple language-tagged
411 * values.
412 *
413 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-summary
414 *
415 * @var string[]|null
416 */
417 protected $summary_map;
418
419 /**
420 * One or more "tags" that have been associated with an objects.
421 * A tag can be any kind of Object.
422 * The key difference between attachment and tag is that the former
423 * implies association by inclusion, while the latter implies
424 * associated by reference.
425 *
426 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-tag
427 *
428 * @var string|null
429 */
430 protected $tag;
431
432 /**
433 * The date and time at which the object was updated
434 *
435 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-updated
436 *
437 * @var string|null xsd:dateTime
438 */
439 protected $updated;
440
441 /**
442 * One or more links to representations of the object.
443 *
444 * @var string|null
445 */
446 protected $url;
447
448 /**
449 * An entity considered to be part of the public primary audience
450 * of an Object
451 *
452 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-to
453 *
454 * @var string|array|null
455 */
456 protected $to;
457
458 /**
459 * An Object that is part of the private primary audience of this
460 * Object.
461 *
462 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-bto
463 *
464 * @var string|array|null
465 */
466 protected $bto;
467
468 /**
469 * An Object that is part of the public secondary audience of this
470 * Object.
471 *
472 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-cc
473 *
474 * @var string|array|null
475 */
476 protected $cc;
477
478 /**
479 * One or more Objects that are part of the private secondary
480 * audience of this Object.
481 *
482 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-bcc
483 *
484 * @var string|array|null
485 */
486 protected $bcc;
487
488 /**
489 * The MIME media type of the value of the content property.
490 * If not specified, the content property is assumed to contain
491 * text/html content.
492 *
493 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-mediatype
494 *
495 * @var string|null
496 */
497 protected $media_type;
498
499 /**
500 * When the object describes a time-bound resource, such as an audio
501 * or video, a meeting, etc., the duration property indicates the
502 * object's approximate duration.
503 * The value MUST be expressed as a xsd:duration as defined by
504 * xmlschema11-2, section 3.3.6 (e.g. a period of 5 seconds is
505 * represented as "PT5S").
506 *
507 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration
508 *
509 * @var string|null
510 */
511 protected $duration;
512
513 /**
514 * Intended to convey some sort of source from which the content
515 * markup was derived, as a form of provenance, or to support
516 * future editing by clients.
517 *
518 * @see https://www.w3.org/TR/activitypub/#source-property
519 *
520 * @var array|null
521 */
522 protected $source;
523
524 /**
525 * A Collection containing objects considered to be responses to
526 * this object.
527 *
528 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-replies
529 *
530 * @var string|array|null
531 */
532 protected $replies;
533
534 /**
535 * A Collection containing objects considered to be likes for
536 * this object.
537 *
538 * @see https://www.w3.org/TR/activitypub/#likes
539 *
540 * @var array|null
541 */
542 protected $likes;
543
544 /**
545 * A Collection containing objects considered to be shares for
546 * this object.
547 *
548 * @see https://www.w3.org/TR/activitypub/#shares
549 *
550 * @var array|null
551 */
552 protected $shares;
553
554 /**
555 * Used to mark an object as containing sensitive content.
556 * Mastodon displays a content warning, requiring users to click
557 * through to view the content.
558 *
559 * @see https://docs.joinmastodon.org/spec/activitypub/#sensitive
560 *
561 * @var boolean|null
562 */
563 protected $sensitive;
564
565 /**
566 * The dcterms namespace.
567 *
568 * @see https://codeberg.org/fediverse/fep/src/branch/main/fep/b2b8/fep-b2b8.md#sensitive
569 * @see https://www.dublincore.org/specifications/dublin-core/dcmi-terms/
570 *
571 * @var array|null
572 */
573 protected $dcterms;
574
575 /**
576 * Interaction policy is an attempt to limit the harmful effects of unwanted replies and
577 * other interactions on a user's posts (e.g., "reply guys").
578 *
579 * It is also used by Mastodon to limit the ability to quote posts.
580 *
581 * @see https://docs.gotosocial.org/en/latest/federation/interaction_policy/
582 * @see https://blog.joinmastodon.org/2025/09/introducing-quote-posts/
583 *
584 * @var array|null
585 */
586 protected $interaction_policy;
587
588 /**
589 * Fediverse Enhancement Proposal 044f: Quote Property
590 *
591 * @see https://codeberg.org/fediverse/fep/src/branch/main/fep/044f/fep-044f.md
592 * @see https://w3id.org/fep/044f#quote
593 *
594 * @var string|null
595 */
596 protected $quote;
597
598 /**
599 * ActivityStreams quoteUrl property.
600 *
601 * @see https://www.w3.org/ns/activitystreams#quoteUrl
602 *
603 * @var string|null
604 */
605 protected $quote_url;
606
607 /**
608 * Fedibird-specific quoteUri property.
609 *
610 * @see https://fedibird.com/ns#quoteUri
611 *
612 * @var string|null
613 */
614 protected $quote_uri;
615
616 /**
617 * Misskey-specific quote property.
618 *
619 * @see https://misskey-hub.net/ns/#_misskey_quote
620 *
621 * @var string|null
622 */
623 protected $_misskey_quote; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
624
625 /**
626 * Generic getter.
627 *
628 * @param string $key The key to get.
629 *
630 * @return mixed The value.
631 */
632 public function get( $key ) {
633 if ( ! $this->has( $key ) ) {
634 return new \WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
635 }
636
637 return parent::get( $key );
638 }
639
640 /**
641 * Generic setter.
642 *
643 * @param string $key The key to set.
644 * @param string $value The value to set.
645 *
646 * @return mixed The value.
647 */
648 public function set( $key, $value ) {
649 if ( ! $this->has( $key ) ) {
650 return new \WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
651 }
652
653 return parent::set( $key, $value );
654 }
655
656 /**
657 * Generic adder.
658 *
659 * @param string $key The key to set.
660 * @param mixed $value The value to add.
661 *
662 * @return mixed The value.
663 */
664 public function add( $key, $value ) {
665 if ( ! $this->has( $key ) ) {
666 return new \WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
667 }
668
669 return parent::add( $key, $value );
670 }
671 }
672