PluginProbe
ActivityPub / 7.8.2
ActivityPub v7.8.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 7.8.2, at includes/activity/class-base-object.php

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