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

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

509 lines 14.9 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 string|null get_actor() Gets one or more entities that performed or are expected to perform the activity.
25 * @method string|null get_attributed_to() Gets the entity attributed as the original author.
26 * @method array|null get_attachment() Gets the attachment property of the object.
27 * @method array|null get_cc() Gets the secondary recipients of the object.
28 * @method string|null get_content() Gets the content property of the object.
29 * @method array|null get_icon() Gets the icon property of the object.
30 * @method string|null get_id() Gets the object's unique global identifier.
31 * @method array|null get_image() Gets the image property of the object.
32 * @method array|string|null get_in_reply_to() Gets the objects this object is in reply to.
33 * @method string|null get_name() Gets the natural language name of the object.
34 * @method Base_Object|string|null get_object() Gets the direct object of the activity.
35 * @method string|null get_published() Gets the date and time the object was published in ISO 8601 format.
36 * @method string|null get_summary() Gets the natural language summary of the object.
37 * @method array|null get_tag() Gets the tag property of the object.
38 * @method array|string|null get_to() Gets the primary recipients of the object.
39 * @method string get_type() Gets the type of the object.
40 * @method string|null get_updated() Gets the date and time the object was updated in ISO 8601 format.
41 * @method string|null get_url() Gets the URL of the object.
42 *
43 * @method string|array add_cc( string|array $cc ) Adds one or more entities to the secondary audience of the object.
44 * @method string|array add_to( string|array $to ) Adds one or more entities to the primary audience of the object.
45 *
46 * @method Base_Object set_actor( string|array $actor ) Sets one or more entities that performed the activity.
47 * @method Base_Object set_attachment( array $attachment ) Sets the attachment property of the object.
48 * @method Base_Object set_attributed_to( string $attributed_to ) Sets the entity attributed as the original author.
49 * @method Base_Object set_cc( array|string $cc ) Sets the secondary recipients of the object.
50 * @method Base_Object set_content( string $content ) Sets the content property of the object.
51 * @method Base_Object set_content_map( array $content_map ) Sets the content property of the object.
52 * @method Base_Object set_icon( array $icon ) Sets the icon property of the object.
53 * @method Base_Object set_id( string $id ) Sets the object's unique global identifier.
54 * @method Base_Object set_image( array $image ) Sets the image property of the object.
55 * @method Base_Object set_name( string $name ) Sets the natural language name of the object.
56 * @method Base_Object set_origin( string $origin ) Sets the origin property of the object.
57 * @method Base_Object set_published( string $published ) Sets the date and time the object was published in ISO 8601 format.
58 * @method Base_Object set_sensitive( bool $sensitive ) Sets the sensitive property of the object.
59 * @method Base_Object set_summary( string $summary ) Sets the natural language summary of the object.
60 * @method Base_Object set_summary_map( array|null $summary_map ) Sets the summary property of the object.
61 * @method Base_Object set_target( string $target ) Sets the target property of the object.
62 * @method Base_Object set_to( array|string $to ) Sets the primary recipients of the object.
63 * @method Base_Object set_type( string $type ) Sets the type of the object.
64 * @method Base_Object set_updated( string $updated ) Sets the date and time the object was updated in ISO 8601 format.
65 * @method Base_Object set_url( string $url ) Sets the URL of the object.
66 */
67 class Base_Object extends Generic_Object {
68 /**
69 * The JSON-LD context for the object.
70 *
71 * @var array
72 */
73 const JSON_LD_CONTEXT = array(
74 'https://www.w3.org/ns/activitystreams',
75 array(
76 'Hashtag' => 'as:Hashtag',
77 'sensitive' => 'as:sensitive',
78 ),
79 );
80
81 /**
82 * The default types for Objects.
83 *
84 * @see https://www.w3.org/TR/activitystreams-vocabulary/#object-types
85 *
86 * @var array
87 */
88 const TYPES = array(
89 'Article',
90 'Audio',
91 'Document',
92 'Event',
93 'Image',
94 'Note',
95 'Page',
96 'Place',
97 'Profile',
98 'Relationship',
99 'Tombstone',
100 'Video',
101 );
102
103 /**
104 * The type of the object.
105 *
106 * @var string
107 */
108 protected $type = 'Object';
109
110 /**
111 * A resource attached or related to an object that potentially
112 * requires special handling.
113 * The intent is to provide a model that is at least semantically
114 * similar to attachments in email.
115 *
116 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-attachment
117 *
118 * @var string|null
119 */
120 protected $attachment;
121
122 /**
123 * One or more entities to which this object is attributed.
124 * The attributed entities might not be Actors. For instance, an
125 * object might be attributed to the completion of another activity.
126 *
127 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-attributedto
128 *
129 * @var string|null
130 */
131 protected $attributed_to;
132
133 /**
134 * One or more entities that represent the total population of
135 * entities for which the object can considered to be relevant.
136 *
137 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-audience
138 *
139 * @var string|null
140 */
141 protected $audience;
142
143 /**
144 * The content or textual representation of the Object encoded as a
145 * JSON string. By default, the value of content is HTML.
146 * The mediaType property can be used in the object to indicate a
147 * different content type.
148 *
149 * The content MAY be expressed using multiple language-tagged
150 * values.
151 *
152 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-content
153 *
154 * @var string|null
155 */
156 protected $content;
157
158 /**
159 * The context within which the object exists or an activity was
160 * performed.
161 * The notion of "context" used is intentionally vague.
162 * The intended function is to serve as a means of grouping objects
163 * and activities that share a common originating context or
164 * purpose. An example could be all activities relating to a common
165 * project or event.
166 *
167 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-context
168 *
169 * @var string|null
170 */
171 protected $context;
172
173 /**
174 * The content MAY be expressed using multiple language-tagged
175 * values.
176 *
177 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-content
178 *
179 * @var array|null
180 */
181 protected $content_map;
182
183 /**
184 * A simple, human-readable, plain-text name for the object.
185 * HTML markup MUST NOT be included.
186 *
187 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-name
188 *
189 * @var string|null xsd:string
190 */
191 protected $name;
192
193 /**
194 * The name MAY be expressed using multiple language-tagged values.
195 *
196 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-name
197 *
198 * @var array|null rdf:langString
199 */
200 protected $name_map;
201
202 /**
203 * The date and time describing the actual or expected ending time
204 * of the object.
205 * When used with an Activity object, for instance, the endTime
206 * property specifies the moment the activity concluded or
207 * is expected to conclude.
208 *
209 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-endtime
210 *
211 * @var string|null
212 */
213 protected $end_time;
214
215 /**
216 * The entity (e.g. an application) that generated the object.
217 *
218 * @var string|null
219 */
220 protected $generator;
221
222 /**
223 * An entity that describes an icon for this object.
224 * The image should have an aspect ratio of one (horizontal)
225 * to one (vertical) and should be suitable for presentation
226 * at a small size.
227 *
228 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-icon
229 *
230 * @var string|array|null
231 */
232 protected $icon;
233
234 /**
235 * An entity that describes an image for this object.
236 * Unlike the icon property, there are no aspect ratio
237 * or display size limitations assumed.
238 *
239 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-image-term
240 *
241 * @var string|array|null
242 */
243 protected $image;
244
245 /**
246 * One or more entities for which this object is considered a
247 * response.
248 *
249 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-inreplyto
250 *
251 * @var string|null
252 */
253 protected $in_reply_to;
254
255 /**
256 * One or more physical or logical locations associated with the
257 * object.
258 *
259 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-location
260 *
261 * @var string|null
262 */
263 protected $location;
264
265 /**
266 * An entity that provides a preview of this object.
267 *
268 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-preview
269 *
270 * @var string|null
271 */
272 protected $preview;
273
274 /**
275 * The date and time at which the object was published
276 *
277 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-published
278 *
279 * @var string|null xsd:dateTime
280 */
281 protected $published;
282
283 /**
284 * The date and time describing the actual or expected starting time
285 * of the object.
286 * When used with an Activity object, for instance, the startTime
287 * property specifies the moment the activity began
288 * or is scheduled to begin.
289 *
290 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-starttime
291 *
292 * @var string|null xsd:dateTime
293 */
294 protected $start_time;
295
296 /**
297 * A natural language summarization of the object encoded as HTML.
298 * Multiple language tagged summaries MAY be provided.
299 *
300 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-summary
301 *
302 * @var string|null
303 */
304 protected $summary;
305
306 /**
307 * The content MAY be expressed using multiple language-tagged
308 * values.
309 *
310 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-summary
311 *
312 * @var string[]|null
313 */
314 protected $summary_map;
315
316 /**
317 * One or more "tags" that have been associated with an objects.
318 * A tag can be any kind of Object.
319 * The key difference between attachment and tag is that the former
320 * implies association by inclusion, while the latter implies
321 * associated by reference.
322 *
323 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-tag
324 *
325 * @var string|null
326 */
327 protected $tag;
328
329 /**
330 * The date and time at which the object was updated
331 *
332 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-updated
333 *
334 * @var string|null xsd:dateTime
335 */
336 protected $updated;
337
338 /**
339 * One or more links to representations of the object.
340 *
341 * @var string|null
342 */
343 protected $url;
344
345 /**
346 * An entity considered to be part of the public primary audience
347 * of an Object
348 *
349 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-to
350 *
351 * @var string|array|null
352 */
353 protected $to;
354
355 /**
356 * An Object that is part of the private primary audience of this
357 * Object.
358 *
359 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-bto
360 *
361 * @var string|array|null
362 */
363 protected $bto;
364
365 /**
366 * An Object that is part of the public secondary audience of this
367 * Object.
368 *
369 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-cc
370 *
371 * @var string|array|null
372 */
373 protected $cc;
374
375 /**
376 * One or more Objects that are part of the private secondary
377 * audience of this Object.
378 *
379 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-bcc
380 *
381 * @var string|array|null
382 */
383 protected $bcc;
384
385 /**
386 * The MIME media type of the value of the content property.
387 * If not specified, the content property is assumed to contain
388 * text/html content.
389 *
390 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-mediatype
391 *
392 * @var string|null
393 */
394 protected $media_type;
395
396 /**
397 * When the object describes a time-bound resource, such as an audio
398 * or video, a meeting, etc, the duration property indicates the
399 * object's approximate duration.
400 * The value MUST be expressed as an xsd:duration as defined by
401 * xmlschema11-2, section 3.3.6 (e.g. a period of 5 seconds is
402 * represented as "PT5S").
403 *
404 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration
405 *
406 * @var string|null
407 */
408 protected $duration;
409
410 /**
411 * Intended to convey some sort of source from which the content
412 * markup was derived, as a form of provenance, or to support
413 * future editing by clients.
414 *
415 * @see https://www.w3.org/TR/activitypub/#source-property
416 *
417 * @var array
418 */
419 protected $source;
420
421 /**
422 * A Collection containing objects considered to be responses to
423 * this object.
424 *
425 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-replies
426 *
427 * @var string|array|null
428 */
429 protected $replies;
430
431 /**
432 * A Collection containing objects considered to be likes for
433 * this object.
434 *
435 * @see https://www.w3.org/TR/activitypub/#likes
436 *
437 * @var array
438 */
439 protected $likes;
440
441 /**
442 * A Collection containing objects considered to be shares for
443 * this object.
444 *
445 * @see https://www.w3.org/TR/activitypub/#shares
446 *
447 * @var array
448 */
449 protected $shares;
450
451 /**
452 * Used to mark an object as containing sensitive content.
453 * Mastodon displays a content warning, requiring users to click
454 * through to view the content.
455 *
456 * @see https://docs.joinmastodon.org/spec/activitypub/#sensitive
457 *
458 * @var boolean
459 */
460 protected $sensitive;
461
462 /**
463 * Generic getter.
464 *
465 * @param string $key The key to get.
466 *
467 * @return mixed The value.
468 */
469 public function get( $key ) {
470 if ( ! $this->has( $key ) ) {
471 return new \WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
472 }
473
474 return parent::get( $key );
475 }
476
477 /**
478 * Generic setter.
479 *
480 * @param string $key The key to set.
481 * @param string $value The value to set.
482 *
483 * @return mixed The value.
484 */
485 public function set( $key, $value ) {
486 if ( ! $this->has( $key ) ) {
487 return new \WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
488 }
489
490 return parent::set( $key, $value );
491 }
492
493 /**
494 * Generic adder.
495 *
496 * @param string $key The key to set.
497 * @param mixed $value The value to add.
498 *
499 * @return mixed The value.
500 */
501 public function add( $key, $value ) {
502 if ( ! $this->has( $key ) ) {
503 return new \WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
504 }
505
506 return parent::add( $key, $value );
507 }
508 }
509