| @@ -2,18 +2,14 @@ | ||
| 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 | - | |
| 13 | -use function Activitypub\camel_to_snake_case; | |
| 14 | -use function Activitypub\snake_to_camel_case; | |
| 15 | - | |
| 16 | 12 | /** |
| 17 | 13 | * Base_Object is an implementation of one of the |
| 18 | 14 | * Activity Streams Core Types. |
| 19 | 15 | * |
| @@ -23,20 +19,169 @@ | ||
| 23 | 19 | * Note: Object is a reserved keyword in PHP. It has been suffixed with |
| 24 | 20 | * 'Base_' for this reason. |
| 25 | 21 | * |
| 26 | 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. | |
| 27 | 110 | */ |
| 28 | -class Base_Object { | |
| 111 | +class Base_Object extends Generic_Object { | |
| 29 | 112 | /** |
| 30 | - * The object's unique global identifier | |
| 113 | + * The JSON-LD context for the object. | |
| 31 | 114 | * |
| 32 | - * @see https://www.w3.org/TR/activitypub/#obj-id | |
| 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. | |
| 33 | 161 | * |
| 34 | - * @var string | |
| 162 | + * @see https://www.w3.org/TR/activitystreams-vocabulary/#object-types | |
| 163 | + * | |
| 164 | + * @var array | |
| 35 | 165 | */ |
| 36 | - protected $id; | |
| 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 | + ); | |
| 37 | 180 | |
| 38 | 181 | /** |
| 182 | + * The type of the object. | |
| 183 | + * | |
| 39 | 184 | * @var string |
| 40 | 185 | */ |
| 41 | 186 | protected $type = 'Object'; |
| 42 | 187 | |
| @@ -47,14 +192,9 @@ | ||
| 47 | 192 | * similar to attachments in email. |
| 48 | 193 | * |
| 49 | 194 | * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-attachment |
| 50 | 195 | * |
| 51 | - * @var string | |
| 52 | - * | ObjectType | |
| 53 | - * | Link | |
| 54 | - * | array<ObjectType> | |
| 55 | - * | array<Link> | |
| 56 | - * | null | |
| 196 | + * @var string|null | |
| 57 | 197 | */ |
| 58 | 198 | protected $attachment; |
| 59 | 199 | |
| 60 | 200 | /** |
| @@ -63,29 +203,19 @@ | ||
| 63 | 203 | * object might be attributed to the completion of another activity. |
| 64 | 204 | * |
| 65 | 205 | * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-attributedto |
| 66 | 206 | * |
| 67 | - * @var string | |
| 68 | - * | ObjectType | |
| 69 | - * | Link | |
| 70 | - * | array<ObjectType> | |
| 71 | - * | array<Link> | |
| 72 | - * | null | |
| 207 | + * @var string|null | |
| 73 | 208 | */ |
| 74 | 209 | protected $attributed_to; |
| 75 | 210 | |
| 76 | 211 | /** |
| 77 | 212 | * One or more entities that represent the total population of |
| 78 | - * entities for which the object can considered to be relevant. | |
| 213 | + * entities for which the object can be considered to be relevant. | |
| 79 | 214 | * |
| 80 | 215 | * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-audience |
| 81 | 216 | * |
| 82 | - * @var string | |
| 83 | - * | ObjectType | |
| 84 | - * | Link | |
| 85 | - * | array<ObjectType> | |
| 86 | - * | array<Link> | |
| 87 | - * | null | |
| 217 | + * @var string|null | |
| 88 | 218 | */ |
| 89 | 219 | protected $audience; |
| 90 | 220 | |
| 91 | 221 | /** |
| @@ -113,12 +243,9 @@ | ||
| 113 | 243 | * project or event. |
| 114 | 244 | * |
| 115 | 245 | * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-context |
| 116 | 246 | * |
| 117 | - * @var string | |
| 118 | - * | ObjectType | |
| 119 | - * | Link | |
| 120 | - * | null | |
| 247 | + * @var string|null | |
| 121 | 248 | */ |
| 122 | 249 | protected $context; |
| 123 | 250 | |
| 124 | 251 | /** |
| @@ -177,14 +304,9 @@ | ||
| 177 | 304 | * at a small size. |
| 178 | 305 | * |
| 179 | 306 | * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-icon |
| 180 | 307 | * |
| 181 | - * @var string | |
| 182 | - * | Image | |
| 183 | - * | Link | |
| 184 | - * | array<Image> | |
| 185 | - * | array<Link> | |
| 186 | - * | null | |
| 308 | + * @var string|array|null | |
| 187 | 309 | */ |
| 188 | 310 | protected $icon; |
| 189 | 311 | |
| 190 | 312 | /** |
| @@ -193,14 +315,9 @@ | ||
| 193 | 315 | * or display size limitations assumed. |
| 194 | 316 | * |
| 195 | 317 | * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-image-term |
| 196 | 318 | * |
| 197 | - * @var string | |
| 198 | - * | Image | |
| 199 | - * | Link | |
| 200 | - * | array<Image> | |
| 201 | - * | array<Link> | |
| 202 | - * | null | |
| 319 | + * @var string|array|null | |
| 203 | 320 | */ |
| 204 | 321 | protected $image; |
| 205 | 322 | |
| 206 | 323 | /** |
| @@ -208,14 +325,9 @@ | ||
| 208 | 325 | * response. |
| 209 | 326 | * |
| 210 | 327 | * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-inreplyto |
| 211 | 328 | * |
| 212 | - * @var string | |
| 213 | - * | ObjectType | |
| 214 | - * | Link | |
| 215 | - * | array<ObjectType> | |
| 216 | - * | array<Link> | |
| 217 | - * | null | |
| 329 | + * @var string|null | |
| 218 | 330 | */ |
| 219 | 331 | protected $in_reply_to; |
| 220 | 332 | |
| 221 | 333 | /** |
| @@ -223,14 +335,9 @@ | ||
| 223 | 335 | * object. |
| 224 | 336 | * |
| 225 | 337 | * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-location |
| 226 | 338 | * |
| 227 | - * @var string | |
| 228 | - * | ObjectType | |
| 229 | - * | Link | |
| 230 | - * | array<ObjectType> | |
| 231 | - * | array<Link> | |
| 232 | - * | null | |
| 339 | + * @var string|null | |
| 233 | 340 | */ |
| 234 | 341 | protected $location; |
| 235 | 342 | |
| 236 | 343 | /** |
| @@ -237,12 +344,9 @@ | ||
| 237 | 344 | * An entity that provides a preview of this object. |
| 238 | 345 | * |
| 239 | 346 | * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-preview |
| 240 | 347 | * |
| 241 | - * @var string | |
| 242 | - * | ObjectType | |
| 243 | - * | Link | |
| 244 | - * | null | |
| 348 | + * @var string|null | |
| 245 | 349 | */ |
| 246 | 350 | protected $preview; |
| 247 | 351 | |
| 248 | 352 | /** |
| @@ -254,21 +358,8 @@ | ||
| 254 | 358 | */ |
| 255 | 359 | protected $published; |
| 256 | 360 | |
| 257 | 361 | /** |
| 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 | 362 | * The date and time describing the actual or expected starting time |
| 272 | 363 | * of the object. |
| 273 | 364 | * When used with an Activity object, for instance, the startTime |
| 274 | 365 | * property specifies the moment the activity began |
| @@ -285,12 +376,9 @@ | ||
| 285 | 376 | * Multiple language tagged summaries MAY be provided. |
| 286 | 377 | * |
| 287 | 378 | * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-summary |
| 288 | 379 | * |
| 289 | - * @var string | |
| 290 | - * | ObjectType | |
| 291 | - * | Link | |
| 292 | - * | null | |
| 380 | + * @var string|null | |
| 293 | 381 | */ |
| 294 | 382 | protected $summary; |
| 295 | 383 | |
| 296 | 384 | /** |
| @@ -298,9 +386,9 @@ | ||
| 298 | 386 | * values. |
| 299 | 387 | * |
| 300 | 388 | * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-summary |
| 301 | 389 | * |
| 302 | - * @var array<string>|null | |
| 390 | + * @var string[]|null | |
| 303 | 391 | */ |
| 304 | 392 | protected $summary_map; |
| 305 | 393 | |
| 306 | 394 | /** |
| @@ -311,14 +399,9 @@ | ||
| 311 | 399 | * associated by reference. |
| 312 | 400 | * |
| 313 | 401 | * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-tag |
| 314 | 402 | * |
| 315 | - * @var string | |
| 316 | - * | ObjectType | |
| 317 | - * | Link | |
| 318 | - * | array<ObjectType> | |
| 319 | - * | array<Link> | |
| 320 | - * | null | |
| 403 | + * @var string|null | |
| 321 | 404 | */ |
| 322 | 405 | protected $tag; |
| 323 | 406 | |
| 324 | 407 | /** |
| @@ -332,13 +415,9 @@ | ||
| 332 | 415 | |
| 333 | 416 | /** |
| 334 | 417 | * One or more links to representations of the object. |
| 335 | 418 | * |
| 336 | - * @var string | |
| 337 | - * | array<string> | |
| 338 | - * | Link | |
| 339 | - * | array<Link> | |
| 340 | - * | null | |
| 419 | + * @var string|null | |
| 341 | 420 | */ |
| 342 | 421 | protected $url; |
| 343 | 422 | |
| 344 | 423 | /** |
| @@ -346,14 +425,9 @@ | ||
| 346 | 425 | * of an Object |
| 347 | 426 | * |
| 348 | 427 | * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-to |
| 349 | 428 | * |
| 350 | - * @var string | |
| 351 | - * | ObjectType | |
| 352 | - * | Link | |
| 353 | - * | array<ObjectType> | |
| 354 | - * | array<Link> | |
| 355 | - * | null | |
| 429 | + * @var string|array|null | |
| 356 | 430 | */ |
| 357 | 431 | protected $to; |
| 358 | 432 | |
| 359 | 433 | /** |
| @@ -361,14 +435,9 @@ | ||
| 361 | 435 | * Object. |
| 362 | 436 | * |
| 363 | 437 | * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-bto |
| 364 | 438 | * |
| 365 | - * @var string | |
| 366 | - * | ObjectType | |
| 367 | - * | Link | |
| 368 | - * | array<ObjectType> | |
| 369 | - * | array<Link> | |
| 370 | - * | null | |
| 439 | + * @var string|array|null | |
| 371 | 440 | */ |
| 372 | 441 | protected $bto; |
| 373 | 442 | |
| 374 | 443 | /** |
| @@ -376,14 +445,9 @@ | ||
| 376 | 445 | * Object. |
| 377 | 446 | * |
| 378 | 447 | * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-cc |
| 379 | 448 | * |
| 380 | - * @var string | |
| 381 | - * | ObjectType | |
| 382 | - * | Link | |
| 383 | - * | array<ObjectType> | |
| 384 | - * | array<Link> | |
| 385 | - * | null | |
| 449 | + * @var string|array|null | |
| 386 | 450 | */ |
| 387 | 451 | protected $cc; |
| 388 | 452 | |
| 389 | 453 | /** |
| @@ -391,14 +455,9 @@ | ||
| 391 | 455 | * audience of this Object. |
| 392 | 456 | * |
| 393 | 457 | * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-bcc |
| 394 | 458 | * |
| 395 | - * @var string | |
| 396 | - * | ObjectType | |
| 397 | - * | Link | |
| 398 | - * | array<ObjectType> | |
| 399 | - * | array<Link> | |
| 400 | - * | null | |
| 459 | + * @var string|array|null | |
| 401 | 460 | */ |
| 402 | 461 | protected $bcc; |
| 403 | 462 | |
| 404 | 463 | /** |
| @@ -413,11 +472,11 @@ | ||
| 413 | 472 | protected $media_type; |
| 414 | 473 | |
| 415 | 474 | /** |
| 416 | 475 | * When the object describes a time-bound resource, such as an audio |
| 417 | - * or video, a meeting, etc, the duration property indicates the | |
| 476 | + * or video, a meeting, etc., the duration property indicates the | |
| 418 | 477 | * object's approximate duration. |
| 419 | - * The value MUST be expressed as an xsd:duration as defined by | |
| 478 | + * The value MUST be expressed as a xsd:duration as defined by | |
| 420 | 479 | * xmlschema11-2, section 3.3.6 (e.g. a period of 5 seconds is |
| 421 | 480 | * represented as "PT5S"). |
| 422 | 481 | * |
| 423 | 482 | * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration |
| @@ -432,247 +491,156 @@ | ||
| 432 | 491 | * future editing by clients. |
| 433 | 492 | * |
| 434 | 493 | * @see https://www.w3.org/TR/activitypub/#source-property |
| 435 | 494 | * |
| 436 | - * @var ObjectType | |
| 495 | + * @var array|null | |
| 437 | 496 | */ |
| 438 | 497 | protected $source; |
| 439 | 498 | |
| 440 | 499 | /** |
| 441 | - * Magic function to implement getter and setter | |
| 500 | + * A Collection containing objects considered to be responses to | |
| 501 | + * this object. | |
| 442 | 502 | * |
| 443 | - * @param string $method The method name. | |
| 444 | - * @param string $params The method params. | |
| 503 | + * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-replies | |
| 445 | 504 | * |
| 446 | - * @return void | |
| 505 | + * @var string|array|null | |
| 447 | 506 | */ |
| 448 | - public function __call( $method, $params ) { | |
| 449 | - $var = \strtolower( \substr( $method, 4 ) ); | |
| 507 | + protected $replies; | |
| 450 | 508 | |
| 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 | 509 | /** |
| 469 | - * Magic function, to transform the object to string. | |
| 510 | + * A Collection containing objects considered to be likes for | |
| 511 | + * this object. | |
| 470 | 512 | * |
| 471 | - * @return string The object id. | |
| 513 | + * @see https://www.w3.org/TR/activitypub/#likes | |
| 514 | + * | |
| 515 | + * @var array|null | |
| 472 | 516 | */ |
| 473 | - public function __toString() { | |
| 474 | - return $this->to_string(); | |
| 475 | - } | |
| 517 | + protected $likes; | |
| 476 | 518 | |
| 477 | 519 | /** |
| 478 | - * Function to transform the object to string. | |
| 520 | + * A Collection containing objects considered to be shares for | |
| 521 | + * this object. | |
| 479 | 522 | * |
| 480 | - * @return string The object id. | |
| 523 | + * @see https://www.w3.org/TR/activitypub/#shares | |
| 524 | + * | |
| 525 | + * @var array|null | |
| 481 | 526 | */ |
| 482 | - public function to_string() { | |
| 483 | - return $this->get_id(); | |
| 484 | - } | |
| 527 | + protected $shares; | |
| 485 | 528 | |
| 486 | 529 | /** |
| 487 | - * Generic getter. | |
| 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. | |
| 488 | 533 | * |
| 489 | - * @param string $key The key to get. | |
| 534 | + * @see https://docs.joinmastodon.org/spec/activitypub/#sensitive | |
| 490 | 535 | * |
| 491 | - * @return mixed The value. | |
| 536 | + * @var boolean|null | |
| 492 | 537 | */ |
| 493 | - public function get( $key ) { | |
| 494 | - if ( ! $this->has( $key ) ) { | |
| 495 | - return new WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) ); | |
| 496 | - } | |
| 538 | + protected $sensitive; | |
| 497 | 539 | |
| 498 | - return call_user_func( array( $this, 'get_' . $key ) ); | |
| 499 | - } | |
| 500 | - | |
| 501 | 540 | /** |
| 502 | - * Check if the object has a key | |
| 541 | + * The dcterms namespace. | |
| 503 | 542 | * |
| 504 | - * @param string $key The key to check. | |
| 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/ | |
| 505 | 545 | * |
| 506 | - * @return boolean True if the object has the key. | |
| 546 | + * @var array|null | |
| 507 | 547 | */ |
| 508 | - public function has( $key ) { | |
| 509 | - return property_exists( $this, $key ); | |
| 510 | - } | |
| 548 | + protected $dcterms; | |
| 511 | 549 | |
| 512 | 550 | /** |
| 513 | - * Generic setter. | |
| 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"). | |
| 514 | 553 | * |
| 515 | - * @param string $key The key to set. | |
| 516 | - * @param string $value The value to set. | |
| 554 | + * It is also used by Mastodon to limit the ability to quote posts. | |
| 517 | 555 | * |
| 518 | - * @return mixed The value. | |
| 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 | |
| 519 | 560 | */ |
| 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 | - } | |
| 561 | + protected $interaction_policy; | |
| 524 | 562 | |
| 525 | - $this->$key = $value; | |
| 526 | - | |
| 527 | - return $this->$key; | |
| 528 | - } | |
| 529 | - | |
| 530 | 563 | /** |
| 531 | - * Generic adder. | |
| 564 | + * Fediverse Enhancement Proposal 044f: Quote Property | |
| 532 | 565 | * |
| 533 | - * @param string $key The key to set. | |
| 534 | - * @param mixed $value The value to add. | |
| 566 | + * @see https://codeberg.org/fediverse/fep/src/branch/main/fep/044f/fep-044f.md | |
| 567 | + * @see https://w3id.org/fep/044f#quote | |
| 535 | 568 | * |
| 536 | - * @return mixed The value. | |
| 569 | + * @var string|null | |
| 537 | 570 | */ |
| 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 | - } | |
| 571 | + protected $quote; | |
| 542 | 572 | |
| 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 | 573 | /** |
| 556 | - * Convert JSON input to an array. | |
| 574 | + * ActivityStreams quoteUrl property. | |
| 557 | 575 | * |
| 558 | - * @return string The JSON string. | |
| 576 | + * @see https://www.w3.org/ns/activitystreams#quoteUrl | |
| 559 | 577 | * |
| 560 | - * @return \Activitypub\Activity\Base_Object An Object built from the JSON string. | |
| 578 | + * @var string|null | |
| 561 | 579 | */ |
| 562 | - public static function init_from_json( $json ) { | |
| 563 | - $array = \json_decode( $json, true ); | |
| 580 | + protected $quote_url; | |
| 564 | 581 | |
| 565 | - if ( ! is_array( $array ) ) { | |
| 566 | - $array = array(); | |
| 567 | - } | |
| 568 | - | |
| 569 | - return self::init_from_array( $array ); | |
| 570 | - } | |
| 571 | - | |
| 572 | 582 | /** |
| 573 | - * Convert JSON input to an array. | |
| 583 | + * Fedibird-specific quoteUri property. | |
| 574 | 584 | * |
| 575 | - * @return string The object array. | |
| 585 | + * @see https://fedibird.com/ns#quoteUri | |
| 576 | 586 | * |
| 577 | - * @return \Activitypub\Activity\Base_Object An Object built from the JSON string. | |
| 587 | + * @var string|null | |
| 578 | 588 | */ |
| 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 | - } | |
| 589 | + protected $quote_uri; | |
| 583 | 590 | |
| 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 | 591 | /** |
| 595 | - * Convert JSON input to an array and pre-fill the object. | |
| 592 | + * Misskey-specific quote property. | |
| 596 | 593 | * |
| 597 | - * @param string $json The JSON string. | |
| 594 | + * @see https://misskey-hub.net/ns/#_misskey_quote | |
| 595 | + * | |
| 596 | + * @var string|null | |
| 598 | 597 | */ |
| 599 | - public function from_json( $json ) { | |
| 600 | - $array = \json_decode( $json, true ); | |
| 598 | + protected $_misskey_quote; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore | |
| 601 | 599 | |
| 602 | - $this->from_array( $array ); | |
| 603 | - } | |
| 604 | - | |
| 605 | 600 | /** |
| 606 | - * Convert JSON input to an array and pre-fill the object. | |
| 601 | + * Generic getter. | |
| 607 | 602 | * |
| 608 | - * @param array $array The array. | |
| 603 | + * @param string $key The key to get. | |
| 604 | + * | |
| 605 | + * @return mixed The value. | |
| 609 | 606 | */ |
| 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 | - } | |
| 607 | + public function get( $key ) { | |
| 608 | + if ( ! $this->has( $key ) ) { | |
| 609 | + return new \WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) ); | |
| 616 | 610 | } |
| 611 | + | |
| 612 | + return parent::get( $key ); | |
| 617 | 613 | } |
| 618 | 614 | |
| 619 | 615 | /** |
| 620 | - * Convert Object to an array. | |
| 616 | + * Generic setter. | |
| 621 | 617 | * |
| 622 | - * It tries to get the object attributes if they exist | |
| 623 | - * and falls back to the getters. Empty values are ignored. | |
| 618 | + * @param string $key The key to set. | |
| 619 | + * @param string $value The value to set. | |
| 624 | 620 | * |
| 625 | - * @return array An array built from the Object. | |
| 621 | + * @return mixed The value. | |
| 626 | 622 | */ |
| 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 | - } | |
| 623 | + public function set( $key, $value ) { | |
| 624 | + if ( ! $this->has( $key ) ) { | |
| 625 | + return new \WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) ); | |
| 650 | 626 | } |
| 651 | 627 | |
| 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; | |
| 628 | + return parent::set( $key, $value ); | |
| 666 | 629 | } |
| 667 | 630 | |
| 668 | 631 | /** |
| 669 | - * Convert Object to JSON. | |
| 632 | + * Generic adder. | |
| 670 | 633 | * |
| 671 | - * @return string The JSON string. | |
| 634 | + * @param string $key The key to set. | |
| 635 | + * @param mixed $value The value to add. | |
| 636 | + * | |
| 637 | + * @return mixed The value. | |
| 672 | 638 | */ |
| 673 | - public function to_json() { | |
| 674 | - $array = $this->to_array(); | |
| 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 | + } | |
| 675 | 643 | |
| 676 | - return \wp_json_encode( $array, \JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_QUOT ); | |
| 644 | + return parent::add( $key, $value ); | |
| 677 | 645 | } |
| 678 | 646 | } |