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

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