| @@ -2,8 +2,10 @@ | ||
| 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 | |
| @@ -13,14 +15,127 @@ | ||
| 13 | 15 | * |
| 14 | 16 | * Represents an individual actor. |
| 15 | 17 | * |
| 16 | 18 | * @see https://www.w3.org/TR/activitystreams-vocabulary/#actor-types |
| 19 | + * | |
| 20 | + * @method string[]|null get_also_known_as() Gets the also known as property of the actor. | |
| 21 | + * @method array|null get_attribution_domains() Gets domains allowed to use fediverse:creator for this actor. | |
| 22 | + * @method bool|null get_discoverable() Gets whether the actor is discoverable. | |
| 23 | + * @method string[]|null get_endpoints() Gets the endpoint property of the actor. | |
| 24 | + * @method string|null get_featured() Gets the featured posts collection of the actor. | |
| 25 | + * @method string|null get_featured_tags() Gets the featured tags collection of the actor. | |
| 26 | + * @method string|null get_followers() Gets the followers collection of the actor. | |
| 27 | + * @method string|null get_following() Gets the following collection of the actor. | |
| 28 | + * @method array|null get_implements() Gets the list of implemented specifications. | |
| 29 | + * @method string|null get_inbox() Gets the inbox property of the actor. | |
| 30 | + * @method bool|null get_indexable() Gets whether the actor is indexable. | |
| 31 | + * @method bool|null get_invisible() Gets whether the actor is invisible. | |
| 32 | + * @method string|null get_liked() Gets the liked collection of the actor. | |
| 33 | + * @method bool|null get_manually_approves_followers() Gets whether the actor manually approves followers. | |
| 34 | + * @method string|null get_moderators() Gets the moderators endpoint URL. | |
| 35 | + * @method string|null get_moved_to() Gets the target of the actor move. | |
| 36 | + * @method string|null get_outbox() Gets the outbox property of the actor. | |
| 37 | + * @method bool|null get_posting_restricted_to_mods() Gets whether posting is restricted to moderators. | |
| 38 | + * @method string|null get_preferred_username() Gets the preferred username of the actor. | |
| 39 | + * @method string|array|null get_public_key() Gets the public key of the actor. | |
| 40 | + * @method array get_streams() Gets the list of supplementary collections. | |
| 41 | + * @method string|null get_webfinger() Gets the WebFinger resource. | |
| 42 | + * | |
| 43 | + * @method Actor set_also_known_as( array $also_known_as ) Sets the also known as property of the actor. | |
| 44 | + * @method Actor set_attribution_domains( array $attribution_domains ) Sets domains allowed to use fediverse:creator for this actor. | |
| 45 | + * @method Actor set_discoverable( bool $discoverable ) Sets whether the actor is discoverable. | |
| 46 | + * @method Actor set_endpoints( string|array $endpoints ) Sets the endpoint property of the actor. | |
| 47 | + * @method Actor set_featured( string $featured ) Sets the featured posts collection of the actor. | |
| 48 | + * @method Actor set_featured_tags( string $featured_tags ) Sets the featured tags collection of the actor. | |
| 49 | + * @method Actor set_followers( string $followers ) Sets the followers collection of the actor. | |
| 50 | + * @method Actor set_following( string $following ) Sets the following collection of the actor. | |
| 51 | + * @method Actor set_implements( array $implements ) Sets the list of implemented specifications. | |
| 52 | + * @method Actor set_inbox( string $inbox ) Sets the inbox property of the actor. | |
| 53 | + * @method Actor set_indexable( bool $indexable ) Sets whether the actor is indexable. | |
| 54 | + * @method Actor set_invisible( bool $invisible ) Sets whether the actor is invisible. | |
| 55 | + * @method Actor set_liked( string $liked ) Sets the liked collection of the actor. | |
| 56 | + * @method Actor set_manually_approves_followers( bool $manually_approves_followers ) Sets whether the actor manually approves followers. | |
| 57 | + * @method Actor set_moderators( string $moderators ) Sets the moderators endpoint URL. | |
| 58 | + * @method Actor set_moved_to( string $moved_to ) Sets the target of the actor move. | |
| 59 | + * @method Actor set_outbox( string $outbox ) Sets the outbox property of the actor. | |
| 60 | + * @method Actor set_posting_restricted_to_mods( bool $posting_restricted_to_mods ) Sets whether posting is restricted to moderators. | |
| 61 | + * @method Actor set_preferred_username( string $preferred_username ) Sets the preferred username of the actor. | |
| 62 | + * @method Actor set_public_key( string|array $public_key ) Sets the public key of the actor. | |
| 63 | + * @method Actor set_streams( array $streams ) Sets the list of supplementary collections. | |
| 64 | + * @method Actor set_webfinger( string $webfinger ) Sets the WebFinger resource. | |
| 17 | 65 | */ |
| 18 | 66 | class Actor extends Base_Object { |
| 67 | + // Reduced context for actors. TODO: still unused. | |
| 68 | + const JSON_LD_CONTEXT = array( | |
| 69 | + 'https://www.w3.org/ns/activitystreams', | |
| 70 | + 'https://w3id.org/security/v1', | |
| 71 | + 'https://purl.archive.org/socialweb/webfinger', | |
| 72 | + array( | |
| 73 | + 'schema' => 'http://schema.org#', | |
| 74 | + 'toot' => 'http://joinmastodon.org/ns#', | |
| 75 | + 'lemmy' => 'https://join-lemmy.org/ns#', | |
| 76 | + 'litepub' => 'http://litepub.social/ns#', | |
| 77 | + 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers', | |
| 78 | + 'PropertyValue' => 'schema:PropertyValue', | |
| 79 | + 'value' => 'schema:value', | |
| 80 | + 'Hashtag' => 'as:Hashtag', | |
| 81 | + 'featured' => array( | |
| 82 | + '@id' => 'toot:featured', | |
| 83 | + '@type' => '@id', | |
| 84 | + ), | |
| 85 | + 'featuredTags' => array( | |
| 86 | + '@id' => 'toot:featuredTags', | |
| 87 | + '@type' => '@id', | |
| 88 | + ), | |
| 89 | + 'moderators' => array( | |
| 90 | + '@id' => 'lemmy:moderators', | |
| 91 | + '@type' => '@id', | |
| 92 | + ), | |
| 93 | + 'alsoKnownAs' => array( | |
| 94 | + '@id' => 'as:alsoKnownAs', | |
| 95 | + '@type' => '@id', | |
| 96 | + ), | |
| 97 | + 'movedTo' => array( | |
| 98 | + '@id' => 'as:movedTo', | |
| 99 | + '@type' => '@id', | |
| 100 | + ), | |
| 101 | + 'attributionDomains' => array( | |
| 102 | + '@id' => 'toot:attributionDomains', | |
| 103 | + '@type' => '@id', | |
| 104 | + ), | |
| 105 | + 'implements' => array( | |
| 106 | + '@id' => 'https://w3id.org/fep/844e/implements', | |
| 107 | + '@type' => '@id', | |
| 108 | + '@container' => '@list', | |
| 109 | + ), | |
| 110 | + 'postingRestrictedToMods' => 'lemmy:postingRestrictedToMods', | |
| 111 | + 'discoverable' => 'toot:discoverable', | |
| 112 | + 'indexable' => 'toot:indexable', | |
| 113 | + 'invisible' => 'litepub:invisible', | |
| 114 | + ), | |
| 115 | + ); | |
| 116 | + | |
| 19 | 117 | /** |
| 118 | + * The default types for Actors. | |
| 119 | + * | |
| 120 | + * @see https://www.w3.org/TR/activitystreams-vocabulary/#actor-types | |
| 121 | + * | |
| 122 | + * @var array | |
| 123 | + */ | |
| 124 | + const TYPES = array( | |
| 125 | + 'Application', | |
| 126 | + 'Group', | |
| 127 | + 'Organization', | |
| 128 | + 'Person', | |
| 129 | + 'Service', | |
| 130 | + ); | |
| 131 | + | |
| 132 | + /** | |
| 133 | + * The type of the object. | |
| 134 | + * | |
| 20 | 135 | * @var string |
| 21 | 136 | */ |
| 22 | - protected $type = 'Person'; | |
| 137 | + protected $type; | |
| 23 | 138 | |
| 24 | 139 | /** |
| 25 | 140 | * A reference to an ActivityStreams OrderedCollection comprised of |
| 26 | 141 | * all the messages received by the actor. |
| @@ -26,10 +141,9 @@ | ||
| 26 | 141 | * all the messages received by the actor. |
| 27 | 142 | * |
| 28 | 143 | * @see https://www.w3.org/TR/activitypub/#inbox |
| 29 | 144 | * |
| 30 | - * @var string | |
| 31 | - * | null | |
| 145 | + * @var string|null | |
| 32 | 146 | */ |
| 33 | 147 | protected $inbox; |
| 34 | 148 | |
| 35 | 149 | /** |
| @@ -37,10 +151,9 @@ | ||
| 37 | 151 | * all the messages produced by the actor. |
| 38 | 152 | * |
| 39 | 153 | * @see https://www.w3.org/TR/activitypub/#outbox |
| 40 | 154 | * |
| 41 | - * @var string | |
| 42 | - * | null | |
| 155 | + * @var string|null | |
| 43 | 156 | */ |
| 44 | 157 | protected $outbox; |
| 45 | 158 | |
| 46 | 159 | /** |
| @@ -105,16 +218,15 @@ | ||
| 105 | 218 | */ |
| 106 | 219 | protected $endpoints; |
| 107 | 220 | |
| 108 | 221 | /** |
| 109 | - * It's not part of the ActivityPub protocol but it's a quite common | |
| 222 | + * It's not part of the ActivityPub protocol, but it's a quite common | |
| 110 | 223 | * practice to handle an actor public key with a publicKey array: |
| 111 | 224 | * [ |
| 112 | - * 'id' => 'https://my-example.com/actor#main-key' | |
| 113 | - * 'owner' => 'https://my-example.com/actor', | |
| 225 | + * 'id' => 'https://my-example.com/actor#main-key' | |
| 226 | + * 'owner' => 'https://my-example.com/actor', | |
| 114 | 227 | * 'publicKeyPem' => '-----BEGIN PUBLIC KEY----- |
| 115 | - * MIIBI [...] | |
| 116 | - * DQIDAQAB | |
| 228 | + * [...] | |
| 117 | 229 | * -----END PUBLIC KEY-----' |
| 118 | 230 | * ] |
| 119 | 231 | * |
| 120 | 232 | * @see https://www.w3.org/wiki/SocialCG/ActivityPub/Authentication_Authorization#Signing_requests_using_HTTP_Signatures |
| @@ -123,10 +235,10 @@ | ||
| 123 | 235 | */ |
| 124 | 236 | protected $public_key; |
| 125 | 237 | |
| 126 | 238 | /** |
| 127 | - * It's not part of the ActivityPub protocol but it's a quite common | |
| 128 | - * practice to lock an account. If anabled, new followers will not be | |
| 239 | + * It's not part of the ActivityPub protocol, but it's a quite common | |
| 240 | + * practice to lock an account. If enabled, new followers will not be | |
| 129 | 241 | * automatically accepted, but will instead require you to manually |
| 130 | 242 | * approve them. |
| 131 | 243 | * |
| 132 | 244 | * WordPress does only support 'false' at the moment. |
| @@ -132,8 +244,129 @@ | ||
| 132 | 244 | * WordPress does only support 'false' at the moment. |
| 133 | 245 | * |
| 134 | 246 | * @see https://docs.joinmastodon.org/spec/activitypub/#as |
| 135 | 247 | * |
| 136 | - * @var boolean | |
| 248 | + * @context as:manuallyApprovesFollowers | |
| 249 | + * | |
| 250 | + * @var boolean|null | |
| 137 | 251 | */ |
| 138 | 252 | protected $manually_approves_followers = false; |
| 253 | + | |
| 254 | + /** | |
| 255 | + * Domains allowed to use `fediverse:creator` for this actor in | |
| 256 | + * published articles. | |
| 257 | + * | |
| 258 | + * @see https://blog.joinmastodon.org/2024/07/highlighting-journalism-on-mastodon/ | |
| 259 | + * | |
| 260 | + * @var array|null | |
| 261 | + */ | |
| 262 | + protected $attribution_domains = null; | |
| 263 | + | |
| 264 | + /** | |
| 265 | + * The target of the actor. | |
| 266 | + * | |
| 267 | + * @var string|null | |
| 268 | + */ | |
| 269 | + protected $moved_to; | |
| 270 | + | |
| 271 | + /** | |
| 272 | + * The alsoKnownAs of the actor. | |
| 273 | + * | |
| 274 | + * @var array|null | |
| 275 | + */ | |
| 276 | + protected $also_known_as; | |
| 277 | + | |
| 278 | + /** | |
| 279 | + * The Featured-Posts. | |
| 280 | + * | |
| 281 | + * @see https://docs.joinmastodon.org/spec/activitypub/#featured | |
| 282 | + * | |
| 283 | + * @context { | |
| 284 | + * "@id": "http://joinmastodon.org/ns#featured", | |
| 285 | + * "@type": "@id" | |
| 286 | + * } | |
| 287 | + * | |
| 288 | + * @var string|null | |
| 289 | + */ | |
| 290 | + protected $featured; | |
| 291 | + | |
| 292 | + /** | |
| 293 | + * The Featured-Tags. | |
| 294 | + * | |
| 295 | + * @see https://docs.joinmastodon.org/spec/activitypub/#featuredTags | |
| 296 | + * | |
| 297 | + * @context { | |
| 298 | + * "@id": "http://joinmastodon.org/ns#featuredTags", | |
| 299 | + * "@type": "@id" | |
| 300 | + * } | |
| 301 | + * | |
| 302 | + * @var string|null | |
| 303 | + */ | |
| 304 | + protected $featured_tags; | |
| 305 | + | |
| 306 | + /** | |
| 307 | + * Whether the User is discoverable. | |
| 308 | + * | |
| 309 | + * @see https://docs.joinmastodon.org/spec/activitypub/#discoverable | |
| 310 | + * | |
| 311 | + * @context http://joinmastodon.org/ns#discoverable | |
| 312 | + * | |
| 313 | + * @var boolean|null | |
| 314 | + */ | |
| 315 | + protected $discoverable; | |
| 316 | + | |
| 317 | + /** | |
| 318 | + * Whether the User is indexable. | |
| 319 | + * | |
| 320 | + * @see https://docs.joinmastodon.org/spec/activitypub/#indexable | |
| 321 | + * | |
| 322 | + * @context http://joinmastodon.org/ns#indexable | |
| 323 | + * | |
| 324 | + * @var boolean|null | |
| 325 | + */ | |
| 326 | + protected $indexable; | |
| 327 | + | |
| 328 | + /** | |
| 329 | + * The WebFinger Resource. | |
| 330 | + * | |
| 331 | + * @see https://codeberg.org/fediverse/fep/src/branch/main/fep/2c59/fep-2c59.md | |
| 332 | + * | |
| 333 | + * @var string|null | |
| 334 | + */ | |
| 335 | + protected $webfinger; | |
| 336 | + | |
| 337 | + /** | |
| 338 | + * URL to the Moderators endpoint. | |
| 339 | + * | |
| 340 | + * @see https://join-lemmy.org/docs/contributors/05-federation.html | |
| 341 | + * | |
| 342 | + * @var string|null | |
| 343 | + */ | |
| 344 | + protected $moderators; | |
| 345 | + | |
| 346 | + /** | |
| 347 | + * Restrict posting to mods. | |
| 348 | + * | |
| 349 | + * @see https://join-lemmy.org/docs/contributors/05-federation.html | |
| 350 | + * | |
| 351 | + * @var boolean|null | |
| 352 | + */ | |
| 353 | + protected $posting_restricted_to_mods; | |
| 354 | + | |
| 355 | + /** | |
| 356 | + * Listing Implemented Specifications on the Application Actor | |
| 357 | + * | |
| 358 | + * @see https://codeberg.org/fediverse/fep/src/branch/main/fep/844e/fep-844e.md | |
| 359 | + * | |
| 360 | + * @var array|null | |
| 361 | + */ | |
| 362 | + protected $implements; | |
| 363 | + | |
| 364 | + /** | |
| 365 | + * Whether the User is invisible. | |
| 366 | + * | |
| 367 | + * @see https://litepub.social/ | |
| 368 | + * | |
| 369 | + * @var boolean|null | |
| 370 | + */ | |
| 371 | + protected $invisible = null; | |
| 139 | 372 | } |