| 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 |
* \Activitypub\Activity\Actor is an implementation of |
| 14 |
* one an Activity Streams Actor. |
| 15 |
* |
| 16 |
* Represents an individual actor. |
| 17 |
* |
| 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. |
| 65 |
*/ |
| 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 |
'gts' => 'https://gotosocial.org/ns#', |
| 78 |
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers', |
| 79 |
'PropertyValue' => 'schema:PropertyValue', |
| 80 |
'value' => 'schema:value', |
| 81 |
'Hashtag' => 'as:Hashtag', |
| 82 |
'featured' => array( |
| 83 |
'@id' => 'toot:featured', |
| 84 |
'@type' => '@id', |
| 85 |
), |
| 86 |
'featuredTags' => array( |
| 87 |
'@id' => 'toot:featuredTags', |
| 88 |
'@type' => '@id', |
| 89 |
), |
| 90 |
'moderators' => array( |
| 91 |
'@id' => 'lemmy:moderators', |
| 92 |
'@type' => '@id', |
| 93 |
), |
| 94 |
'alsoKnownAs' => array( |
| 95 |
'@id' => 'as:alsoKnownAs', |
| 96 |
'@type' => '@id', |
| 97 |
), |
| 98 |
'movedTo' => array( |
| 99 |
'@id' => 'as:movedTo', |
| 100 |
'@type' => '@id', |
| 101 |
), |
| 102 |
'attributionDomains' => array( |
| 103 |
'@id' => 'toot:attributionDomains', |
| 104 |
'@type' => '@id', |
| 105 |
), |
| 106 |
'implements' => array( |
| 107 |
'@id' => 'https://w3id.org/fep/844e/implements', |
| 108 |
'@type' => '@id', |
| 109 |
'@container' => '@list', |
| 110 |
), |
| 111 |
'interactionPolicy' => array( |
| 112 |
'@id' => 'gts:interactionPolicy', |
| 113 |
'@type' => '@id', |
| 114 |
), |
| 115 |
'canFeature' => array( |
| 116 |
'@id' => 'https://w3id.org/fep/7aa9#canFeature', |
| 117 |
'@type' => '@id', |
| 118 |
), |
| 119 |
'automaticApproval' => array( |
| 120 |
'@id' => 'gts:automaticApproval', |
| 121 |
'@type' => '@id', |
| 122 |
), |
| 123 |
'postingRestrictedToMods' => 'lemmy:postingRestrictedToMods', |
| 124 |
'discoverable' => 'toot:discoverable', |
| 125 |
'indexable' => 'toot:indexable', |
| 126 |
'invisible' => 'litepub:invisible', |
| 127 |
), |
| 128 |
); |
| 129 |
|
| 130 |
/** |
| 131 |
* The default types for Actors. |
| 132 |
* |
| 133 |
* @see https://www.w3.org/TR/activitystreams-vocabulary/#actor-types |
| 134 |
* |
| 135 |
* @var array |
| 136 |
*/ |
| 137 |
const TYPES = array( |
| 138 |
'Application', |
| 139 |
'Group', |
| 140 |
'Organization', |
| 141 |
'Person', |
| 142 |
'Service', |
| 143 |
); |
| 144 |
|
| 145 |
/** |
| 146 |
* The type of the object. |
| 147 |
* |
| 148 |
* @var string |
| 149 |
*/ |
| 150 |
protected $type; |
| 151 |
|
| 152 |
/** |
| 153 |
* A reference to an ActivityStreams OrderedCollection comprised of |
| 154 |
* all the messages received by the actor. |
| 155 |
* |
| 156 |
* @see https://www.w3.org/TR/activitypub/#inbox |
| 157 |
* |
| 158 |
* @var string|null |
| 159 |
*/ |
| 160 |
protected $inbox; |
| 161 |
|
| 162 |
/** |
| 163 |
* A reference to an ActivityStreams OrderedCollection comprised of |
| 164 |
* all the messages produced by the actor. |
| 165 |
* |
| 166 |
* @see https://www.w3.org/TR/activitypub/#outbox |
| 167 |
* |
| 168 |
* @var string|null |
| 169 |
*/ |
| 170 |
protected $outbox; |
| 171 |
|
| 172 |
/** |
| 173 |
* A link to an ActivityStreams collection of the actors that this |
| 174 |
* actor is following. |
| 175 |
* |
| 176 |
* @see https://www.w3.org/TR/activitypub/#following |
| 177 |
* |
| 178 |
* @var string |
| 179 |
*/ |
| 180 |
protected $following; |
| 181 |
|
| 182 |
/** |
| 183 |
* A link to an ActivityStreams collection of the actors that |
| 184 |
* follow this actor. |
| 185 |
* |
| 186 |
* @see https://www.w3.org/TR/activitypub/#followers |
| 187 |
* |
| 188 |
* @var string |
| 189 |
*/ |
| 190 |
protected $followers; |
| 191 |
|
| 192 |
/** |
| 193 |
* A link to an ActivityStreams collection of objects this actor has |
| 194 |
* liked. |
| 195 |
* |
| 196 |
* @see https://www.w3.org/TR/activitypub/#liked |
| 197 |
* |
| 198 |
* @var string |
| 199 |
*/ |
| 200 |
protected $liked; |
| 201 |
|
| 202 |
/** |
| 203 |
* A list of supplementary Collections which may be of interest. |
| 204 |
* |
| 205 |
* @see https://www.w3.org/TR/activitypub/#streams-property |
| 206 |
* |
| 207 |
* @var array |
| 208 |
*/ |
| 209 |
protected $streams = array(); |
| 210 |
|
| 211 |
/** |
| 212 |
* A short username which may be used to refer to the actor, with no |
| 213 |
* uniqueness guarantees. |
| 214 |
* |
| 215 |
* @see https://www.w3.org/TR/activitypub/#preferredUsername |
| 216 |
* |
| 217 |
* @var string|null |
| 218 |
*/ |
| 219 |
protected $preferred_username; |
| 220 |
|
| 221 |
/** |
| 222 |
* A JSON object which maps additional typically server/domain-wide |
| 223 |
* endpoints which may be useful either for this actor or someone |
| 224 |
* referencing this actor. This mapping may be nested inside the |
| 225 |
* actor document as the value or may be a link to a JSON-LD |
| 226 |
* document with these properties. |
| 227 |
* |
| 228 |
* @see https://www.w3.org/TR/activitypub/#endpoints |
| 229 |
* |
| 230 |
* @var string|array|null |
| 231 |
*/ |
| 232 |
protected $endpoints; |
| 233 |
|
| 234 |
/** |
| 235 |
* It's not part of the ActivityPub protocol, but it's a quite common |
| 236 |
* practice to handle an actor public key with a publicKey array: |
| 237 |
* [ |
| 238 |
* 'id' => 'https://my-example.com/actor#main-key' |
| 239 |
* 'owner' => 'https://my-example.com/actor', |
| 240 |
* 'publicKeyPem' => '-----BEGIN PUBLIC KEY----- |
| 241 |
* [...] |
| 242 |
* -----END PUBLIC KEY-----' |
| 243 |
* ] |
| 244 |
* |
| 245 |
* @see https://www.w3.org/wiki/SocialCG/ActivityPub/Authentication_Authorization#Signing_requests_using_HTTP_Signatures |
| 246 |
* |
| 247 |
* @var string|array|null |
| 248 |
*/ |
| 249 |
protected $public_key; |
| 250 |
|
| 251 |
/** |
| 252 |
* It's not part of the ActivityPub protocol, but it's a quite common |
| 253 |
* practice to lock an account. If enabled, new followers will not be |
| 254 |
* automatically accepted, but will instead require you to manually |
| 255 |
* approve them. |
| 256 |
* |
| 257 |
* WordPress does only support 'false' at the moment. |
| 258 |
* |
| 259 |
* @see https://docs.joinmastodon.org/spec/activitypub/#as |
| 260 |
* |
| 261 |
* @context as:manuallyApprovesFollowers |
| 262 |
* |
| 263 |
* @var boolean|null |
| 264 |
*/ |
| 265 |
protected $manually_approves_followers = false; |
| 266 |
|
| 267 |
/** |
| 268 |
* Domains allowed to use `fediverse:creator` for this actor in |
| 269 |
* published articles. |
| 270 |
* |
| 271 |
* @see https://blog.joinmastodon.org/2024/07/highlighting-journalism-on-mastodon/ |
| 272 |
* |
| 273 |
* @var array|null |
| 274 |
*/ |
| 275 |
protected $attribution_domains = null; |
| 276 |
|
| 277 |
/** |
| 278 |
* The target of the actor. |
| 279 |
* |
| 280 |
* @var string|null |
| 281 |
*/ |
| 282 |
protected $moved_to; |
| 283 |
|
| 284 |
/** |
| 285 |
* The alsoKnownAs of the actor. |
| 286 |
* |
| 287 |
* @var array|null |
| 288 |
*/ |
| 289 |
protected $also_known_as; |
| 290 |
|
| 291 |
/** |
| 292 |
* The Featured-Posts. |
| 293 |
* |
| 294 |
* @see https://docs.joinmastodon.org/spec/activitypub/#featured |
| 295 |
* |
| 296 |
* @context { |
| 297 |
* "@id": "http://joinmastodon.org/ns#featured", |
| 298 |
* "@type": "@id" |
| 299 |
* } |
| 300 |
* |
| 301 |
* @var string|null |
| 302 |
*/ |
| 303 |
protected $featured; |
| 304 |
|
| 305 |
/** |
| 306 |
* The Featured-Tags. |
| 307 |
* |
| 308 |
* @see https://docs.joinmastodon.org/spec/activitypub/#featuredTags |
| 309 |
* |
| 310 |
* @context { |
| 311 |
* "@id": "http://joinmastodon.org/ns#featuredTags", |
| 312 |
* "@type": "@id" |
| 313 |
* } |
| 314 |
* |
| 315 |
* @var string|null |
| 316 |
*/ |
| 317 |
protected $featured_tags; |
| 318 |
|
| 319 |
/** |
| 320 |
* Whether the User is discoverable. |
| 321 |
* |
| 322 |
* @see https://docs.joinmastodon.org/spec/activitypub/#discoverable |
| 323 |
* |
| 324 |
* @context http://joinmastodon.org/ns#discoverable |
| 325 |
* |
| 326 |
* @var boolean|null |
| 327 |
*/ |
| 328 |
protected $discoverable; |
| 329 |
|
| 330 |
/** |
| 331 |
* Whether the User is indexable. |
| 332 |
* |
| 333 |
* @see https://docs.joinmastodon.org/spec/activitypub/#indexable |
| 334 |
* |
| 335 |
* @context http://joinmastodon.org/ns#indexable |
| 336 |
* |
| 337 |
* @var boolean|null |
| 338 |
*/ |
| 339 |
protected $indexable; |
| 340 |
|
| 341 |
/** |
| 342 |
* The WebFinger Resource. |
| 343 |
* |
| 344 |
* @see https://codeberg.org/fediverse/fep/src/branch/main/fep/2c59/fep-2c59.md |
| 345 |
* |
| 346 |
* @var string|null |
| 347 |
*/ |
| 348 |
protected $webfinger; |
| 349 |
|
| 350 |
/** |
| 351 |
* URL to the Moderators endpoint. |
| 352 |
* |
| 353 |
* @see https://join-lemmy.org/docs/contributors/05-federation.html |
| 354 |
* |
| 355 |
* @var string|null |
| 356 |
*/ |
| 357 |
protected $moderators; |
| 358 |
|
| 359 |
/** |
| 360 |
* Restrict posting to mods. |
| 361 |
* |
| 362 |
* @see https://join-lemmy.org/docs/contributors/05-federation.html |
| 363 |
* |
| 364 |
* @var boolean|null |
| 365 |
*/ |
| 366 |
protected $posting_restricted_to_mods; |
| 367 |
|
| 368 |
/** |
| 369 |
* Listing Implemented Specifications on the Application Actor |
| 370 |
* |
| 371 |
* @see https://codeberg.org/fediverse/fep/src/branch/main/fep/844e/fep-844e.md |
| 372 |
* |
| 373 |
* @var array|null |
| 374 |
*/ |
| 375 |
protected $implements; |
| 376 |
|
| 377 |
/** |
| 378 |
* Whether the User is invisible. |
| 379 |
* |
| 380 |
* @see https://litepub.social/ |
| 381 |
* |
| 382 |
* @var boolean|null |
| 383 |
*/ |
| 384 |
protected $invisible = null; |
| 385 |
} |
| 386 |
|