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