modified file upgrade-temp-backup
This commit is contained in:
@ -0,0 +1,314 @@
|
||||
<?php
|
||||
/**
|
||||
* Inspired by the PHP ActivityPub Library by @Landrok
|
||||
*
|
||||
* @link https://github.com/landrok/activitypub
|
||||
*
|
||||
* @package Activitypub
|
||||
*/
|
||||
|
||||
namespace Activitypub\Activity;
|
||||
|
||||
use Activitypub\Activity\Extended_Object\Event;
|
||||
use Activitypub\Activity\Extended_Object\Place;
|
||||
|
||||
/**
|
||||
* \Activitypub\Activity\Activity implements the common
|
||||
* attributes of an Activity.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-core/#activities
|
||||
* @see https://www.w3.org/TR/activitystreams-core/#intransitiveactivities
|
||||
*
|
||||
* @method string|array get_actor() Gets one or more entities that performed or are expected to perform the activity.
|
||||
* @method string|array|null get_instrument() Gets one or more objects used in the completion of an Activity.
|
||||
* @method Base_Object|string|array|null get_object() Gets the direct object of the activity.
|
||||
* @method string|string[]|null get_origin() Gets the origin property of the activity.
|
||||
* @method array|null get_replies() Gets the collection of responses to this activity.
|
||||
* @method string|null get_result() Gets the result property of the activity.
|
||||
* @method string|string[]|null get_target() Gets the target property of the activity.
|
||||
*
|
||||
* @method Activity set_actor( string|array $actor ) Sets one or more entities that performed the activity.
|
||||
* @method Activity set_instrument( string|array $instrument ) Sets one or more objects used in the completion of an Activity.
|
||||
* @method Activity set_origin( string|array|null $origin ) Sets the origin property of the activity.
|
||||
* @method Activity set_replies( array $replies ) Sets the collection of responses to this activity.
|
||||
* @method Activity set_result( string|null $result ) Sets the result property of the activity.
|
||||
* @method Activity set_target( string|array|null $target ) Sets the target property of the activity.
|
||||
*/
|
||||
class Activity extends Base_Object {
|
||||
const JSON_LD_CONTEXT = array(
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
array(
|
||||
'toot' => 'http://joinmastodon.org/ns#',
|
||||
'QuoteRequest' => 'toot:QuoteRequest',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* The default types for Activities.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#activity-types
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
const TYPES = array(
|
||||
'Accept',
|
||||
'Add',
|
||||
'Announce',
|
||||
'Arrive',
|
||||
'Block',
|
||||
'Create',
|
||||
'Delete',
|
||||
'Dislike',
|
||||
'Follow',
|
||||
'Flag',
|
||||
'Ignore',
|
||||
'Invite',
|
||||
'Join',
|
||||
'Leave',
|
||||
'Like',
|
||||
'Listen',
|
||||
'Move',
|
||||
'Offer',
|
||||
'QuoteRequest', // @see https://codeberg.org/fediverse/fep/src/branch/main/fep/044f/fep-044f.md
|
||||
'Read',
|
||||
'Reject',
|
||||
'Remove',
|
||||
'TentativeAccept',
|
||||
'TentativeReject',
|
||||
'Travel',
|
||||
'Undo',
|
||||
'Update',
|
||||
'View',
|
||||
);
|
||||
|
||||
/**
|
||||
* The type of the object.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $type = 'Activity';
|
||||
|
||||
/**
|
||||
* Describes the direct object of the activity.
|
||||
* For instance, in the activity "John added a movie to his
|
||||
* wishlist", the object of the activity is the movie added.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-object-term
|
||||
*
|
||||
* @var string|Base_Object|array|null
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Describes one or more entities that either performed or are
|
||||
* expected to perform the activity.
|
||||
* Any single activity can have multiple actors.
|
||||
* The actor MAY be specified using an indirect Link.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-actor
|
||||
*
|
||||
* @var string|array
|
||||
*/
|
||||
protected $actor;
|
||||
|
||||
/**
|
||||
* The indirect object, or target, of the activity.
|
||||
* The precise meaning of the target is largely dependent on the
|
||||
* type of action being described but will often be the object of
|
||||
* the English preposition "to".
|
||||
* For instance, in the activity "John added a movie to his
|
||||
* wishlist", the target of the activity is John's wishlist.
|
||||
* An activity can have more than one target.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-target
|
||||
*
|
||||
* @var string|array|null
|
||||
*/
|
||||
protected $target;
|
||||
|
||||
/**
|
||||
* Describes the result of the activity.
|
||||
* For instance, if a particular action results in the creation of
|
||||
* a new resource, the result property can be used to describe
|
||||
* that new resource.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-result
|
||||
*
|
||||
* @var string|Base_Object|null
|
||||
*/
|
||||
protected $result;
|
||||
|
||||
/**
|
||||
* Identifies a Collection containing objects considered to be responses
|
||||
* to this object.
|
||||
* WordPress has a strong core system of approving replies. We only include
|
||||
* approved replies here.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-replies
|
||||
*
|
||||
* @var array|null
|
||||
*/
|
||||
protected $replies;
|
||||
|
||||
/**
|
||||
* An indirect object of the activity from which the
|
||||
* activity is directed.
|
||||
* The precise meaning of the origin is the object of the English
|
||||
* preposition "from".
|
||||
* For instance, in the activity "John moved an item to List B
|
||||
* from List A", the origin of the activity is "List A".
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-origin
|
||||
*
|
||||
* @var string|array|null
|
||||
*/
|
||||
protected $origin;
|
||||
|
||||
/**
|
||||
* One or more objects used (or to be used) in the completion of an
|
||||
* Activity.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-instrument
|
||||
*
|
||||
* @var string|array|null
|
||||
*/
|
||||
protected $instrument;
|
||||
|
||||
/**
|
||||
* Set the object and copy Object properties to the Activity.
|
||||
*
|
||||
* Any to, bto, cc, bcc, and audience properties specified on the object
|
||||
* MUST be copied over to the new "Create" activity by the server.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitypub/#object-without-create
|
||||
*
|
||||
* @param array|string|Base_Object|Activity|Actor|null $data Activity object.
|
||||
*/
|
||||
public function set_object( $data ) {
|
||||
$object = $data;
|
||||
|
||||
// Convert array to appropriate object type.
|
||||
if ( is_array( $data ) ) {
|
||||
if ( array_is_list( $data ) ) {
|
||||
$object = array_map( array( $this, 'maybe_convert_to_object' ), $data );
|
||||
} else {
|
||||
$object = $this->maybe_convert_to_object( $data );
|
||||
}
|
||||
}
|
||||
|
||||
$this->set( 'object', $object );
|
||||
$this->pre_fill_activity_from_object();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills the Activity with the specified activity object.
|
||||
*/
|
||||
public function pre_fill_activity_from_object() {
|
||||
$object = $this->get_object();
|
||||
|
||||
// Check if `$object` is a URL and use it to generate an ID then.
|
||||
if ( is_string( $object ) && filter_var( $object, FILTER_VALIDATE_URL ) && ! $this->get_id() ) {
|
||||
$this->set( 'id', $object . '#activity-' . strtolower( $this->get_type() ) . '-' . time() );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if `$object` is an object and copy some properties otherwise do nothing.
|
||||
if ( ! is_object( $object ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( array( 'to', 'bto', 'cc', 'bcc', 'audience' ) as $i ) {
|
||||
$value = $object->get( $i );
|
||||
if ( $value && ! $this->get( $i ) ) {
|
||||
$this->set( $i, $value );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $object->get_published() && ! $this->get_published() ) {
|
||||
$this->set( 'published', $object->get_published() );
|
||||
}
|
||||
|
||||
if ( $object->get_updated() && ! $this->get_updated() ) {
|
||||
$this->set( 'updated', $object->get_updated() );
|
||||
}
|
||||
|
||||
if ( $object->get_attributed_to() && ! $this->get_actor() ) {
|
||||
$this->set( 'actor', $object->get_attributed_to() );
|
||||
}
|
||||
|
||||
if ( $this->get_type() !== 'Announce' && $object->get_in_reply_to() && ! $this->get_in_reply_to() ) {
|
||||
$this->set( 'in_reply_to', $object->get_in_reply_to() );
|
||||
}
|
||||
|
||||
if ( $object->get_interaction_policy() && ! $this->get_interaction_policy() ) {
|
||||
$this->set( 'interaction_policy', $object->get_interaction_policy() );
|
||||
}
|
||||
|
||||
if ( $object->get_id() && ! $this->get_id() ) {
|
||||
$id = strtok( $object->get_id(), '#' );
|
||||
if ( $object->get_updated() ) {
|
||||
$updated = $object->get_updated();
|
||||
} elseif ( $object->get_published() ) {
|
||||
$updated = $object->get_published();
|
||||
} else {
|
||||
$updated = time();
|
||||
}
|
||||
$this->set( 'id', $id . '#activity-' . strtolower( $this->get_type() ) . '-' . $updated );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The context of an Activity is usually just the context of the object it contains.
|
||||
*
|
||||
* @return array $context A compacted JSON-LD context.
|
||||
*/
|
||||
public function get_json_ld_context() {
|
||||
if ( \is_object( $this->object ) ) {
|
||||
$class = get_class( $this->object );
|
||||
if ( $class && $class::JSON_LD_CONTEXT ) {
|
||||
// Without php 5.6 support this could be just: 'return $this->object::JSON_LD_CONTEXT;'.
|
||||
return $class::JSON_LD_CONTEXT;
|
||||
}
|
||||
}
|
||||
|
||||
return static::JSON_LD_CONTEXT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert data to the appropriate object type if it has an ActivityPub type.
|
||||
*
|
||||
* @param array|string|Base_Object|Activity|Actor|null $data The data to convert.
|
||||
*
|
||||
* @return Activity|Actor|Base_Object|Generic_Object|string|\WP_Error|null The converted object or original data.
|
||||
*/
|
||||
private function maybe_convert_to_object( $data ) {
|
||||
if ( ! is_array( $data ) ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$type = $data['type'] ?? null;
|
||||
|
||||
if ( in_array( $type, self::TYPES, true ) ) {
|
||||
$object = self::init_from_array( $data );
|
||||
} elseif ( in_array( $type, Actor::TYPES, true ) ) {
|
||||
$object = Actor::init_from_array( $data );
|
||||
} elseif ( in_array( $type, Base_Object::TYPES, true ) ) {
|
||||
switch ( $type ) {
|
||||
case 'Event':
|
||||
$object = Event::init_from_array( $data );
|
||||
break;
|
||||
case 'Place':
|
||||
$object = Place::init_from_array( $data );
|
||||
break;
|
||||
default:
|
||||
$object = Base_Object::init_from_array( $data );
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$object = Generic_Object::init_from_array( $data );
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,372 @@
|
||||
<?php
|
||||
/**
|
||||
* Inspired by the PHP ActivityPub Library by @Landrok
|
||||
*
|
||||
* @link https://github.com/landrok/activitypub
|
||||
*
|
||||
* @package Activitypub
|
||||
*/
|
||||
|
||||
namespace Activitypub\Activity;
|
||||
|
||||
/**
|
||||
* \Activitypub\Activity\Actor is an implementation of
|
||||
* one an Activity Streams Actor.
|
||||
*
|
||||
* Represents an individual actor.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#actor-types
|
||||
*
|
||||
* @method string[]|null get_also_known_as() Gets the also known as property of the actor.
|
||||
* @method array|null get_attribution_domains() Gets domains allowed to use fediverse:creator for this actor.
|
||||
* @method bool|null get_discoverable() Gets whether the actor is discoverable.
|
||||
* @method string[]|null get_endpoints() Gets the endpoint property of the actor.
|
||||
* @method string|null get_featured() Gets the featured posts collection of the actor.
|
||||
* @method string|null get_featured_tags() Gets the featured tags collection of the actor.
|
||||
* @method string|null get_followers() Gets the followers collection of the actor.
|
||||
* @method string|null get_following() Gets the following collection of the actor.
|
||||
* @method array|null get_implements() Gets the list of implemented specifications.
|
||||
* @method string|null get_inbox() Gets the inbox property of the actor.
|
||||
* @method bool|null get_indexable() Gets whether the actor is indexable.
|
||||
* @method bool|null get_invisible() Gets whether the actor is invisible.
|
||||
* @method string|null get_liked() Gets the liked collection of the actor.
|
||||
* @method bool|null get_manually_approves_followers() Gets whether the actor manually approves followers.
|
||||
* @method string|null get_moderators() Gets the moderators endpoint URL.
|
||||
* @method string|null get_moved_to() Gets the target of the actor move.
|
||||
* @method string|null get_outbox() Gets the outbox property of the actor.
|
||||
* @method bool|null get_posting_restricted_to_mods() Gets whether posting is restricted to moderators.
|
||||
* @method string|null get_preferred_username() Gets the preferred username of the actor.
|
||||
* @method string|array|null get_public_key() Gets the public key of the actor.
|
||||
* @method array get_streams() Gets the list of supplementary collections.
|
||||
* @method string|null get_webfinger() Gets the WebFinger resource.
|
||||
*
|
||||
* @method Actor set_also_known_as( array $also_known_as ) Sets the also known as property of the actor.
|
||||
* @method Actor set_attribution_domains( array $attribution_domains ) Sets domains allowed to use fediverse:creator for this actor.
|
||||
* @method Actor set_discoverable( bool $discoverable ) Sets whether the actor is discoverable.
|
||||
* @method Actor set_endpoints( string|array $endpoints ) Sets the endpoint property of the actor.
|
||||
* @method Actor set_featured( string $featured ) Sets the featured posts collection of the actor.
|
||||
* @method Actor set_featured_tags( string $featured_tags ) Sets the featured tags collection of the actor.
|
||||
* @method Actor set_followers( string $followers ) Sets the followers collection of the actor.
|
||||
* @method Actor set_following( string $following ) Sets the following collection of the actor.
|
||||
* @method Actor set_implements( array $implements ) Sets the list of implemented specifications.
|
||||
* @method Actor set_inbox( string $inbox ) Sets the inbox property of the actor.
|
||||
* @method Actor set_indexable( bool $indexable ) Sets whether the actor is indexable.
|
||||
* @method Actor set_invisible( bool $invisible ) Sets whether the actor is invisible.
|
||||
* @method Actor set_liked( string $liked ) Sets the liked collection of the actor.
|
||||
* @method Actor set_manually_approves_followers( bool $manually_approves_followers ) Sets whether the actor manually approves followers.
|
||||
* @method Actor set_moderators( string $moderators ) Sets the moderators endpoint URL.
|
||||
* @method Actor set_moved_to( string $moved_to ) Sets the target of the actor move.
|
||||
* @method Actor set_outbox( string $outbox ) Sets the outbox property of the actor.
|
||||
* @method Actor set_posting_restricted_to_mods( bool $posting_restricted_to_mods ) Sets whether posting is restricted to moderators.
|
||||
* @method Actor set_preferred_username( string $preferred_username ) Sets the preferred username of the actor.
|
||||
* @method Actor set_public_key( string|array $public_key ) Sets the public key of the actor.
|
||||
* @method Actor set_streams( array $streams ) Sets the list of supplementary collections.
|
||||
* @method Actor set_webfinger( string $webfinger ) Sets the WebFinger resource.
|
||||
*/
|
||||
class Actor extends Base_Object {
|
||||
// Reduced context for actors. TODO: still unused.
|
||||
const JSON_LD_CONTEXT = array(
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
'https://w3id.org/security/v1',
|
||||
'https://purl.archive.org/socialweb/webfinger',
|
||||
array(
|
||||
'schema' => 'http://schema.org#',
|
||||
'toot' => 'http://joinmastodon.org/ns#',
|
||||
'lemmy' => 'https://join-lemmy.org/ns#',
|
||||
'litepub' => 'http://litepub.social/ns#',
|
||||
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
|
||||
'PropertyValue' => 'schema:PropertyValue',
|
||||
'value' => 'schema:value',
|
||||
'Hashtag' => 'as:Hashtag',
|
||||
'featured' => array(
|
||||
'@id' => 'toot:featured',
|
||||
'@type' => '@id',
|
||||
),
|
||||
'featuredTags' => array(
|
||||
'@id' => 'toot:featuredTags',
|
||||
'@type' => '@id',
|
||||
),
|
||||
'moderators' => array(
|
||||
'@id' => 'lemmy:moderators',
|
||||
'@type' => '@id',
|
||||
),
|
||||
'alsoKnownAs' => array(
|
||||
'@id' => 'as:alsoKnownAs',
|
||||
'@type' => '@id',
|
||||
),
|
||||
'movedTo' => array(
|
||||
'@id' => 'as:movedTo',
|
||||
'@type' => '@id',
|
||||
),
|
||||
'attributionDomains' => array(
|
||||
'@id' => 'toot:attributionDomains',
|
||||
'@type' => '@id',
|
||||
),
|
||||
'implements' => array(
|
||||
'@id' => 'https://w3id.org/fep/844e/implements',
|
||||
'@type' => '@id',
|
||||
'@container' => '@list',
|
||||
),
|
||||
'postingRestrictedToMods' => 'lemmy:postingRestrictedToMods',
|
||||
'discoverable' => 'toot:discoverable',
|
||||
'indexable' => 'toot:indexable',
|
||||
'invisible' => 'litepub:invisible',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* The default types for Actors.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#actor-types
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
const TYPES = array(
|
||||
'Application',
|
||||
'Group',
|
||||
'Organization',
|
||||
'Person',
|
||||
'Service',
|
||||
);
|
||||
|
||||
/**
|
||||
* The type of the object.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* A reference to an ActivityStreams OrderedCollection comprised of
|
||||
* all the messages received by the actor.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitypub/#inbox
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $inbox;
|
||||
|
||||
/**
|
||||
* A reference to an ActivityStreams OrderedCollection comprised of
|
||||
* all the messages produced by the actor.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitypub/#outbox
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $outbox;
|
||||
|
||||
/**
|
||||
* A link to an ActivityStreams collection of the actors that this
|
||||
* actor is following.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitypub/#following
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $following;
|
||||
|
||||
/**
|
||||
* A link to an ActivityStreams collection of the actors that
|
||||
* follow this actor.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitypub/#followers
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $followers;
|
||||
|
||||
/**
|
||||
* A link to an ActivityStreams collection of objects this actor has
|
||||
* liked.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitypub/#liked
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $liked;
|
||||
|
||||
/**
|
||||
* A list of supplementary Collections which may be of interest.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitypub/#streams-property
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $streams = array();
|
||||
|
||||
/**
|
||||
* A short username which may be used to refer to the actor, with no
|
||||
* uniqueness guarantees.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitypub/#preferredUsername
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $preferred_username;
|
||||
|
||||
/**
|
||||
* A JSON object which maps additional typically server/domain-wide
|
||||
* endpoints which may be useful either for this actor or someone
|
||||
* referencing this actor. This mapping may be nested inside the
|
||||
* actor document as the value or may be a link to a JSON-LD
|
||||
* document with these properties.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitypub/#endpoints
|
||||
*
|
||||
* @var string|array|null
|
||||
*/
|
||||
protected $endpoints;
|
||||
|
||||
/**
|
||||
* It's not part of the ActivityPub protocol, but it's a quite common
|
||||
* practice to handle an actor public key with a publicKey array:
|
||||
* [
|
||||
* 'id' => 'https://my-example.com/actor#main-key'
|
||||
* 'owner' => 'https://my-example.com/actor',
|
||||
* 'publicKeyPem' => '-----BEGIN PUBLIC KEY-----
|
||||
* [...]
|
||||
* -----END PUBLIC KEY-----'
|
||||
* ]
|
||||
*
|
||||
* @see https://www.w3.org/wiki/SocialCG/ActivityPub/Authentication_Authorization#Signing_requests_using_HTTP_Signatures
|
||||
*
|
||||
* @var string|array|null
|
||||
*/
|
||||
protected $public_key;
|
||||
|
||||
/**
|
||||
* It's not part of the ActivityPub protocol, but it's a quite common
|
||||
* practice to lock an account. If enabled, new followers will not be
|
||||
* automatically accepted, but will instead require you to manually
|
||||
* approve them.
|
||||
*
|
||||
* WordPress does only support 'false' at the moment.
|
||||
*
|
||||
* @see https://docs.joinmastodon.org/spec/activitypub/#as
|
||||
*
|
||||
* @context as:manuallyApprovesFollowers
|
||||
*
|
||||
* @var boolean|null
|
||||
*/
|
||||
protected $manually_approves_followers = false;
|
||||
|
||||
/**
|
||||
* Domains allowed to use `fediverse:creator` for this actor in
|
||||
* published articles.
|
||||
*
|
||||
* @see https://blog.joinmastodon.org/2024/07/highlighting-journalism-on-mastodon/
|
||||
*
|
||||
* @var array|null
|
||||
*/
|
||||
protected $attribution_domains = null;
|
||||
|
||||
/**
|
||||
* The target of the actor.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $moved_to;
|
||||
|
||||
/**
|
||||
* The alsoKnownAs of the actor.
|
||||
*
|
||||
* @var array|null
|
||||
*/
|
||||
protected $also_known_as;
|
||||
|
||||
/**
|
||||
* The Featured-Posts.
|
||||
*
|
||||
* @see https://docs.joinmastodon.org/spec/activitypub/#featured
|
||||
*
|
||||
* @context {
|
||||
* "@id": "http://joinmastodon.org/ns#featured",
|
||||
* "@type": "@id"
|
||||
* }
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $featured;
|
||||
|
||||
/**
|
||||
* The Featured-Tags.
|
||||
*
|
||||
* @see https://docs.joinmastodon.org/spec/activitypub/#featuredTags
|
||||
*
|
||||
* @context {
|
||||
* "@id": "http://joinmastodon.org/ns#featuredTags",
|
||||
* "@type": "@id"
|
||||
* }
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $featured_tags;
|
||||
|
||||
/**
|
||||
* Whether the User is discoverable.
|
||||
*
|
||||
* @see https://docs.joinmastodon.org/spec/activitypub/#discoverable
|
||||
*
|
||||
* @context http://joinmastodon.org/ns#discoverable
|
||||
*
|
||||
* @var boolean|null
|
||||
*/
|
||||
protected $discoverable;
|
||||
|
||||
/**
|
||||
* Whether the User is indexable.
|
||||
*
|
||||
* @see https://docs.joinmastodon.org/spec/activitypub/#indexable
|
||||
*
|
||||
* @context http://joinmastodon.org/ns#indexable
|
||||
*
|
||||
* @var boolean|null
|
||||
*/
|
||||
protected $indexable;
|
||||
|
||||
/**
|
||||
* The WebFinger Resource.
|
||||
*
|
||||
* @see https://codeberg.org/fediverse/fep/src/branch/main/fep/2c59/fep-2c59.md
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $webfinger;
|
||||
|
||||
/**
|
||||
* URL to the Moderators endpoint.
|
||||
*
|
||||
* @see https://join-lemmy.org/docs/contributors/05-federation.html
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $moderators;
|
||||
|
||||
/**
|
||||
* Restrict posting to mods.
|
||||
*
|
||||
* @see https://join-lemmy.org/docs/contributors/05-federation.html
|
||||
*
|
||||
* @var boolean|null
|
||||
*/
|
||||
protected $posting_restricted_to_mods;
|
||||
|
||||
/**
|
||||
* Listing Implemented Specifications on the Application Actor
|
||||
*
|
||||
* @see https://codeberg.org/fediverse/fep/src/branch/main/fep/844e/fep-844e.md
|
||||
*
|
||||
* @var array|null
|
||||
*/
|
||||
protected $implements;
|
||||
|
||||
/**
|
||||
* Whether the User is invisible.
|
||||
*
|
||||
* @see https://litepub.social/
|
||||
*
|
||||
* @var boolean|null
|
||||
*/
|
||||
protected $invisible = null;
|
||||
}
|
||||
@ -0,0 +1,674 @@
|
||||
<?php
|
||||
/**
|
||||
* Inspired by the PHP ActivityPub Library by @Landrok
|
||||
*
|
||||
* @link https://github.com/landrok/activitypub
|
||||
*
|
||||
* @package Activitypub
|
||||
*/
|
||||
|
||||
namespace Activitypub\Activity;
|
||||
|
||||
use Activitypub\Activity\Extended_Object\Place;
|
||||
|
||||
/**
|
||||
* Base_Object is an implementation of one of the
|
||||
* Activity Streams Core Types.
|
||||
*
|
||||
* The Object is the primary base type for the Activity Streams
|
||||
* vocabulary.
|
||||
*
|
||||
* Note: Object is a reserved keyword in PHP. It has been suffixed with
|
||||
* 'Base_' for this reason.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-core/#object
|
||||
*
|
||||
* @method array|string|null get_attachment() Gets the attachment property of the object.
|
||||
* @method array|string|null get_attributed_to() Gets the entity attributed as the original author.
|
||||
* @method string|null get_audience() Gets the total population of entities for which the object can be considered relevant.
|
||||
* @method string[]|string|null get_bcc() Gets the private secondary audience of the object.
|
||||
* @method string[]|string|null get_bto() Gets the private primary audience of the object.
|
||||
* @method string[]|string|null get_cc() Gets the secondary recipients of the object.
|
||||
* @method string|null get_content() Gets the content property of the object.
|
||||
* @method string[]|null get_content_map() Gets the content map property of the object.
|
||||
* @method string|null get_context() Gets the context within which the object exists.
|
||||
* @method array|null get_dcterms() Gets the Dublin Core terms property of the object.
|
||||
* @method string|null get_duration() Gets the duration property of time-bound resources.
|
||||
* @method string|null get_end_time() Gets the date and time describing the ending time of the object.
|
||||
* @method string|null get_generator() Gets the entity that generated the object.
|
||||
* @method string[]|null get_icon() Gets the icon property of the object.
|
||||
* @method string|null get_id() Gets the object's unique global identifier.
|
||||
* @method string[]|null get_image() Gets the image property of the object.
|
||||
* @method string[]|string|null get_in_reply_to() Gets the objects this object is in reply to.
|
||||
* @method array|null get_interaction_policy() Gets the interaction policy property of the object.
|
||||
* @method array|null get_likes() Gets the collection of likes for this object.
|
||||
* @method array|string|null|Place get_location() Gets the physical or logical locations associated with the object.
|
||||
* @method string|null get_media_type() Gets the MIME media type of the content property.
|
||||
* @method string|null get_name() Gets the natural language name of the object.
|
||||
* @method string[]|null get_name_map() Gets the name map property of the object.
|
||||
* @method string|null get_preview() Gets the entity that provides a preview of this object.
|
||||
* @method string|null get_published() Gets the date and time the object was published in ISO 8601 format.
|
||||
* @method string|null get_quote() Gets the quote property of the object (FEP-044f).
|
||||
* @method string|null get_quote_url() Gets the quoteUrl property of the object.
|
||||
* @method string|null get_quote_uri() Gets the quoteUri property of the object.
|
||||
* @method string|null get__misskey_quote() Gets the _misskey_quote property of the object.
|
||||
* @method string|array|null get_replies() Gets the collection of responses to this object.
|
||||
* @method bool|null get_sensitive() Gets the sensitive property of the object.
|
||||
* @method array|null get_shares() Gets the collection of shares for this object.
|
||||
* @method array|null get_source() Gets the source property indicating content markup derivation.
|
||||
* @method string|null get_start_time() Gets the date and time describing the starting time of the object.
|
||||
* @method string|null get_summary() Gets the natural language summary of the object.
|
||||
* @method string[]|null get_summary_map() Gets the summary map property of the object.
|
||||
* @method array[]|null get_tag() Gets the tag property of the object.
|
||||
* @method string[]|string|null get_to() Gets the primary recipients of the object.
|
||||
* @method string get_type() Gets the type of the object.
|
||||
* @method string|null get_updated() Gets the date and time the object was updated in ISO 8601 format.
|
||||
* @method string|null get_url() Gets the URL of the object.
|
||||
* @method string|null get_former_type() Gets the former type of a Tombstone object.
|
||||
* @method string|null get_deleted() Gets the date and time the object was deleted in ISO 8601 format.
|
||||
*
|
||||
* @method string|string[] add_cc( string|array $cc ) Adds one or more entities to the secondary audience of the object.
|
||||
* @method string|string[] add_to( string|array $to ) Adds one or more entities to the primary audience of the object.
|
||||
*
|
||||
* @method Base_Object set_attachment( array $attachment ) Sets the attachment property of the object.
|
||||
* @method Base_Object set_attributed_to( string $attributed_to ) Sets the entity attributed as the original author.
|
||||
* @method Base_Object set_audience( string $audience ) Sets the total population of entities for which the object can be considered relevant.
|
||||
* @method Base_Object set_bcc( array|string $bcc ) Sets the private secondary audience of the object.
|
||||
* @method Base_Object set_bto( array|string $bto ) Sets the private primary audience of the object.
|
||||
* @method Base_Object set_cc( array|string $cc ) Sets the secondary recipients of the object.
|
||||
* @method Base_Object set_content( string $content ) Sets the content property of the object.
|
||||
* @method Base_Object set_content_map( array $content_map ) Sets the content property of the object.
|
||||
* @method Base_Object set_context( string $context ) Sets the context within which the object exists.
|
||||
* @method Base_Object set_dcterms( array $dcterms ) Sets the Dublin Core terms property of the object.
|
||||
* @method Base_Object set_duration( string $duration ) Sets the duration property of time-bound resources.
|
||||
* @method Base_Object set_end_time( string $end_time ) Sets the date and time describing the ending time of the object.
|
||||
* @method Base_Object set_generator( string $generator ) Sets the entity that generated the object.
|
||||
* @method Base_Object set_icon( array $icon ) Sets the icon property of the object.
|
||||
* @method Base_Object set_id( string $id ) Sets the object's unique global identifier.
|
||||
* @method Base_Object set_image( array $image ) Sets the image property of the object.
|
||||
* @method Base_Object set_in_reply_to( string|string[] $in_reply_to ) Sets the is in reply to property of the object.
|
||||
* @method Base_Object set_interaction_policy( array|null $policy ) Sets the interaction policy property of the object.
|
||||
* @method Base_Object set_likes( array $likes ) Sets the collection of likes for this object.
|
||||
* @method Base_Object set_location( array|string|Place $location ) Sets the physical or logical locations associated with the object.
|
||||
* @method Base_Object set_media_type( string $media_type ) Sets the MIME media type of the content property.
|
||||
* @method Base_Object set_name( string $name ) Sets the natural language name of the object.
|
||||
* @method Base_Object set_name_map( array|null $name_map ) Sets the name map property of the object.
|
||||
* @method Base_Object set_preview( string $preview ) Sets the entity that provides a preview of this object.
|
||||
* @method Base_Object set_published( string|null $published ) Sets the date and time the object was published in ISO 8601 format.
|
||||
* @method Base_Object set_quote( string $quote ) Sets the quote property of the object (FEP-044f).
|
||||
* @method Base_Object set_quote_url( string $quote_url ) Sets the quoteUrl property of the object.
|
||||
* @method Base_Object set_quote_uri( string $quote_uri ) Sets the quoteUri property of the object.
|
||||
* @method Base_Object set__misskey_quote( mixed $misskey_quote ) Sets the _misskey_quote property of the object.
|
||||
* @method Base_Object set_replies( string|array $replies ) Sets the collection of responses to this object.
|
||||
* @method Base_Object set_sensitive( bool|null $sensitive ) Sets the sensitive property of the object.
|
||||
* @method Base_Object set_shares( array $shares ) Sets the collection of shares for this object.
|
||||
* @method Base_Object set_source( array $source ) Sets the source property indicating content markup derivation.
|
||||
* @method Base_Object set_start_time( string $start_time ) Sets the date and time describing the starting time of the object.
|
||||
* @method Base_Object set_summary( string $summary ) Sets the natural language summary of the object.
|
||||
* @method Base_Object set_summary_map( array|null $summary_map ) Sets the summary property of the object.
|
||||
* @method Base_Object set_tag( array|null $tag ) Sets the tag property of the object.
|
||||
* @method Base_Object set_to( string|string[] $to ) Sets the primary recipients of the object.
|
||||
* @method Base_Object set_type( string $type ) Sets the type of the object.
|
||||
* @method Base_Object set_updated( string $updated ) Sets the date and time the object was updated in ISO 8601 format.
|
||||
* @method Base_Object set_url( string $url ) Sets the URL of the object.
|
||||
* @method Base_Object set_former_type( string $former_type ) Sets the former type of a Tombstone object.
|
||||
* @method Base_Object set_deleted( string $deleted ) Sets the date and time the object was deleted in ISO 8601 format.
|
||||
*/
|
||||
class Base_Object extends Generic_Object {
|
||||
/**
|
||||
* The JSON-LD context for the object.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
const JSON_LD_CONTEXT = array(
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
array(
|
||||
'Hashtag' => 'as:Hashtag',
|
||||
'sensitive' => 'as:sensitive',
|
||||
'dcterms' => 'http://purl.org/dc/terms/',
|
||||
'gts' => 'https://gotosocial.org/ns#',
|
||||
'schema' => 'http://schema.org/',
|
||||
'exifData' => 'schema:exifData',
|
||||
'PropertyValue' => 'schema:PropertyValue',
|
||||
'interactionPolicy' => array(
|
||||
'@id' => 'gts:interactionPolicy',
|
||||
'@type' => '@id',
|
||||
),
|
||||
'canQuote' => array(
|
||||
'@id' => 'gts:canQuote',
|
||||
'@type' => '@id',
|
||||
),
|
||||
'canReply' => array(
|
||||
'@id' => 'gts:canReply',
|
||||
'@type' => '@id',
|
||||
),
|
||||
'canLike' => array(
|
||||
'@id' => 'gts:canLike',
|
||||
'@type' => '@id',
|
||||
),
|
||||
'canAnnounce' => array(
|
||||
'@id' => 'gts:canAnnounce',
|
||||
'@type' => '@id',
|
||||
),
|
||||
'automaticApproval' => array(
|
||||
'@id' => 'gts:automaticApproval',
|
||||
'@type' => '@id',
|
||||
),
|
||||
'manualApproval' => array(
|
||||
'@id' => 'gts:manualApproval',
|
||||
'@type' => '@id',
|
||||
),
|
||||
'always' => array(
|
||||
'@id' => 'gts:always',
|
||||
'@type' => '@id',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* The default types for Objects.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#object-types
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
const TYPES = array(
|
||||
'Article',
|
||||
'Audio',
|
||||
'Document',
|
||||
'Event',
|
||||
'Image',
|
||||
'Note',
|
||||
'Page',
|
||||
'Place',
|
||||
'Profile',
|
||||
'Relationship',
|
||||
'Tombstone',
|
||||
'Video',
|
||||
);
|
||||
|
||||
/**
|
||||
* The type of the object.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $type = 'Object';
|
||||
|
||||
/**
|
||||
* A resource attached or related to an object that potentially
|
||||
* requires special handling.
|
||||
* The intent is to provide a model that is at least semantically
|
||||
* similar to attachments in email.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-attachment
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $attachment;
|
||||
|
||||
/**
|
||||
* One or more entities to which this object is attributed.
|
||||
* The attributed entities might not be Actors. For instance, an
|
||||
* object might be attributed to the completion of another activity.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-attributedto
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $attributed_to;
|
||||
|
||||
/**
|
||||
* One or more entities that represent the total population of
|
||||
* entities for which the object can be considered to be relevant.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-audience
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $audience;
|
||||
|
||||
/**
|
||||
* The content or textual representation of the Object encoded as a
|
||||
* JSON string. By default, the value of content is HTML.
|
||||
* The mediaType property can be used in the object to indicate a
|
||||
* different content type.
|
||||
*
|
||||
* The content MAY be expressed using multiple language-tagged
|
||||
* values.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-content
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $content;
|
||||
|
||||
/**
|
||||
* The context within which the object exists or an activity was
|
||||
* performed.
|
||||
* The notion of "context" used is intentionally vague.
|
||||
* The intended function is to serve as a means of grouping objects
|
||||
* and activities that share a common originating context or
|
||||
* purpose. An example could be all activities relating to a common
|
||||
* project or event.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-context
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $context;
|
||||
|
||||
/**
|
||||
* The content MAY be expressed using multiple language-tagged
|
||||
* values.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-content
|
||||
*
|
||||
* @var array|null
|
||||
*/
|
||||
protected $content_map;
|
||||
|
||||
/**
|
||||
* The date and time at which the object was deleted.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-deleted
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $deleted;
|
||||
|
||||
/**
|
||||
* The former type of the object. Used in Tombstone objects to
|
||||
* indicate the type of the object prior to deletion.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-formertype
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $former_type;
|
||||
|
||||
/**
|
||||
* A simple, human-readable, plain-text name for the object.
|
||||
* HTML markup MUST NOT be included.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-name
|
||||
*
|
||||
* @var string|null xsd:string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* The name MAY be expressed using multiple language-tagged values.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-name
|
||||
*
|
||||
* @var array|null rdf:langString
|
||||
*/
|
||||
protected $name_map;
|
||||
|
||||
/**
|
||||
* The date and time describing the actual or expected ending time
|
||||
* of the object.
|
||||
* When used with an Activity object, for instance, the endTime
|
||||
* property specifies the moment the activity concluded or
|
||||
* is expected to conclude.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-endtime
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $end_time;
|
||||
|
||||
/**
|
||||
* The entity (e.g. an application) that generated the object.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $generator;
|
||||
|
||||
/**
|
||||
* An entity that describes an icon for this object.
|
||||
* The image should have an aspect ratio of one (horizontal)
|
||||
* to one (vertical) and should be suitable for presentation
|
||||
* at a small size.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-icon
|
||||
*
|
||||
* @var string|array|null
|
||||
*/
|
||||
protected $icon;
|
||||
|
||||
/**
|
||||
* An entity that describes an image for this object.
|
||||
* Unlike the icon property, there are no aspect ratio
|
||||
* or display size limitations assumed.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-image-term
|
||||
*
|
||||
* @var string|array|null
|
||||
*/
|
||||
protected $image;
|
||||
|
||||
/**
|
||||
* One or more entities for which this object is considered a
|
||||
* response.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-inreplyto
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $in_reply_to;
|
||||
|
||||
/**
|
||||
* One or more physical or logical locations associated with the
|
||||
* object.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-location
|
||||
*
|
||||
* @var string|null|Place
|
||||
*/
|
||||
protected $location;
|
||||
|
||||
/**
|
||||
* An entity that provides a preview of this object.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-preview
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $preview;
|
||||
|
||||
/**
|
||||
* The date and time at which the object was published
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-published
|
||||
*
|
||||
* @var string|null xsd:dateTime
|
||||
*/
|
||||
protected $published;
|
||||
|
||||
/**
|
||||
* The date and time describing the actual or expected starting time
|
||||
* of the object.
|
||||
* When used with an Activity object, for instance, the startTime
|
||||
* property specifies the moment the activity began
|
||||
* or is scheduled to begin.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-starttime
|
||||
*
|
||||
* @var string|null xsd:dateTime
|
||||
*/
|
||||
protected $start_time;
|
||||
|
||||
/**
|
||||
* A natural language summarization of the object encoded as HTML.
|
||||
* Multiple language tagged summaries MAY be provided.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-summary
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $summary;
|
||||
|
||||
/**
|
||||
* The content MAY be expressed using multiple language-tagged
|
||||
* values.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-summary
|
||||
*
|
||||
* @var string[]|null
|
||||
*/
|
||||
protected $summary_map;
|
||||
|
||||
/**
|
||||
* One or more "tags" that have been associated with an objects.
|
||||
* A tag can be any kind of Object.
|
||||
* The key difference between attachment and tag is that the former
|
||||
* implies association by inclusion, while the latter implies
|
||||
* associated by reference.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-tag
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $tag;
|
||||
|
||||
/**
|
||||
* The date and time at which the object was updated
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-updated
|
||||
*
|
||||
* @var string|null xsd:dateTime
|
||||
*/
|
||||
protected $updated;
|
||||
|
||||
/**
|
||||
* One or more links to representations of the object.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $url;
|
||||
|
||||
/**
|
||||
* An entity considered to be part of the public primary audience
|
||||
* of an Object
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-to
|
||||
*
|
||||
* @var string|array|null
|
||||
*/
|
||||
protected $to;
|
||||
|
||||
/**
|
||||
* An Object that is part of the private primary audience of this
|
||||
* Object.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-bto
|
||||
*
|
||||
* @var string|array|null
|
||||
*/
|
||||
protected $bto;
|
||||
|
||||
/**
|
||||
* An Object that is part of the public secondary audience of this
|
||||
* Object.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-cc
|
||||
*
|
||||
* @var string|array|null
|
||||
*/
|
||||
protected $cc;
|
||||
|
||||
/**
|
||||
* One or more Objects that are part of the private secondary
|
||||
* audience of this Object.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-bcc
|
||||
*
|
||||
* @var string|array|null
|
||||
*/
|
||||
protected $bcc;
|
||||
|
||||
/**
|
||||
* The MIME media type of the value of the content property.
|
||||
* If not specified, the content property is assumed to contain
|
||||
* text/html content.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-mediatype
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $media_type;
|
||||
|
||||
/**
|
||||
* When the object describes a time-bound resource, such as an audio
|
||||
* or video, a meeting, etc., the duration property indicates the
|
||||
* object's approximate duration.
|
||||
* The value MUST be expressed as a xsd:duration as defined by
|
||||
* xmlschema11-2, section 3.3.6 (e.g. a period of 5 seconds is
|
||||
* represented as "PT5S").
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $duration;
|
||||
|
||||
/**
|
||||
* Intended to convey some sort of source from which the content
|
||||
* markup was derived, as a form of provenance, or to support
|
||||
* future editing by clients.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitypub/#source-property
|
||||
*
|
||||
* @var array|null
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
/**
|
||||
* A Collection containing objects considered to be responses to
|
||||
* this object.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-replies
|
||||
*
|
||||
* @var string|array|null
|
||||
*/
|
||||
protected $replies;
|
||||
|
||||
/**
|
||||
* A Collection containing objects considered to be likes for
|
||||
* this object.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitypub/#likes
|
||||
*
|
||||
* @var array|null
|
||||
*/
|
||||
protected $likes;
|
||||
|
||||
/**
|
||||
* A Collection containing objects considered to be shares for
|
||||
* this object.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitypub/#shares
|
||||
*
|
||||
* @var array|null
|
||||
*/
|
||||
protected $shares;
|
||||
|
||||
/**
|
||||
* Used to mark an object as containing sensitive content.
|
||||
* Mastodon displays a content warning, requiring users to click
|
||||
* through to view the content.
|
||||
*
|
||||
* @see https://docs.joinmastodon.org/spec/activitypub/#sensitive
|
||||
*
|
||||
* @var boolean|null
|
||||
*/
|
||||
protected $sensitive;
|
||||
|
||||
/**
|
||||
* The dcterms namespace.
|
||||
*
|
||||
* @see https://codeberg.org/fediverse/fep/src/branch/main/fep/b2b8/fep-b2b8.md#sensitive
|
||||
* @see https://www.dublincore.org/specifications/dublin-core/dcmi-terms/
|
||||
*
|
||||
* @var array|null
|
||||
*/
|
||||
protected $dcterms;
|
||||
|
||||
/**
|
||||
* Interaction policy is an attempt to limit the harmful effects of unwanted replies and
|
||||
* other interactions on a user's posts (e.g., "reply guys").
|
||||
*
|
||||
* It is also used by Mastodon to limit the ability to quote posts.
|
||||
*
|
||||
* @see https://docs.gotosocial.org/en/latest/federation/interaction_policy/
|
||||
* @see https://blog.joinmastodon.org/2025/09/introducing-quote-posts/
|
||||
*
|
||||
* @var array|null
|
||||
*/
|
||||
protected $interaction_policy;
|
||||
|
||||
/**
|
||||
* Fediverse Enhancement Proposal 044f: Quote Property
|
||||
*
|
||||
* @see https://codeberg.org/fediverse/fep/src/branch/main/fep/044f/fep-044f.md
|
||||
* @see https://w3id.org/fep/044f#quote
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $quote;
|
||||
|
||||
/**
|
||||
* ActivityStreams quoteUrl property.
|
||||
*
|
||||
* @see https://www.w3.org/ns/activitystreams#quoteUrl
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $quote_url;
|
||||
|
||||
/**
|
||||
* Fedibird-specific quoteUri property.
|
||||
*
|
||||
* @see https://fedibird.com/ns#quoteUri
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $quote_uri;
|
||||
|
||||
/**
|
||||
* Misskey-specific quote property.
|
||||
*
|
||||
* @see https://misskey-hub.net/ns/#_misskey_quote
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $_misskey_quote; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
|
||||
|
||||
/**
|
||||
* Generic getter.
|
||||
*
|
||||
* @param string $key The key to get.
|
||||
*
|
||||
* @return mixed The value.
|
||||
*/
|
||||
public function get( $key ) {
|
||||
if ( ! $this->has( $key ) ) {
|
||||
return new \WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
|
||||
}
|
||||
|
||||
return parent::get( $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic setter.
|
||||
*
|
||||
* @param string $key The key to set.
|
||||
* @param string $value The value to set.
|
||||
*
|
||||
* @return mixed The value.
|
||||
*/
|
||||
public function set( $key, $value ) {
|
||||
if ( ! $this->has( $key ) ) {
|
||||
return new \WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
|
||||
}
|
||||
|
||||
return parent::set( $key, $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic adder.
|
||||
*
|
||||
* @param string $key The key to set.
|
||||
* @param mixed $value The value to add.
|
||||
*
|
||||
* @return mixed The value.
|
||||
*/
|
||||
public function add( $key, $value ) {
|
||||
if ( ! $this->has( $key ) ) {
|
||||
return new \WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
|
||||
}
|
||||
|
||||
return parent::add( $key, $value );
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,381 @@
|
||||
<?php
|
||||
/**
|
||||
* Generic Object.
|
||||
*
|
||||
* @package Activitypub
|
||||
*/
|
||||
|
||||
namespace Activitypub\Activity;
|
||||
|
||||
use function Activitypub\camel_to_snake_case;
|
||||
use function Activitypub\snake_to_camel_case;
|
||||
|
||||
/**
|
||||
* Generic Object.
|
||||
*
|
||||
* This class is used to create Generic Objects.
|
||||
* It is used to create objects that might be unknown by the plugin but
|
||||
* conform to the ActivityStreams vocabulary.
|
||||
*
|
||||
* Provides generic magic methods for getting, setting, and adding properties
|
||||
* through __call(). Specific property documentation is in the classes where
|
||||
* the properties are actually defined.
|
||||
*
|
||||
* @since 5.3.0
|
||||
*/
|
||||
#[\AllowDynamicProperties]
|
||||
class Generic_Object {
|
||||
/**
|
||||
* The JSON-LD context for the object.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
const JSON_LD_CONTEXT = array(
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
);
|
||||
|
||||
/**
|
||||
* The object's unique global identifier
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitypub/#obj-id
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* Magic function, to transform the object to string.
|
||||
*
|
||||
* @return string The object id.
|
||||
*/
|
||||
public function __toString() {
|
||||
return $this->to_string();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to transform the object to string.
|
||||
*
|
||||
* @return string The object id.
|
||||
*/
|
||||
public function to_string() {
|
||||
return $this->get_id();
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic function to implement getter and setter.
|
||||
*
|
||||
* @param string $method The method name.
|
||||
* @param string $params The method params.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call( $method, $params ) {
|
||||
$var = \strtolower( \substr( $method, 4 ) );
|
||||
|
||||
if ( \strncasecmp( $method, 'get', 3 ) === 0 ) {
|
||||
if ( ! $this->has( $var ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->$var;
|
||||
}
|
||||
|
||||
if ( \strncasecmp( $method, 'set', 3 ) === 0 ) {
|
||||
return $this->set( $var, $params[0] );
|
||||
}
|
||||
|
||||
if ( \strncasecmp( $method, 'add', 3 ) === 0 ) {
|
||||
return $this->add( $var, $params[0] );
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic getter.
|
||||
*
|
||||
* @param string $key The key to get.
|
||||
*
|
||||
* @return mixed The value.
|
||||
*/
|
||||
public function get( $key ) {
|
||||
return call_user_func( array( $this, 'get_' . $key ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic setter.
|
||||
*
|
||||
* @param string $key The key to set.
|
||||
* @param string $value The value to set.
|
||||
*
|
||||
* @return mixed The value.
|
||||
*/
|
||||
public function set( $key, $value ) {
|
||||
$this->$key = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic adder.
|
||||
*
|
||||
* @param string $key The key to set.
|
||||
* @param mixed $value The value to add.
|
||||
*
|
||||
* @return mixed|void The value.
|
||||
*/
|
||||
public function add( $key, $value ) {
|
||||
if ( empty( $value ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! isset( $this->$key ) ) {
|
||||
$this->$key = array();
|
||||
}
|
||||
|
||||
if ( is_string( $this->$key ) ) {
|
||||
$this->$key = array( $this->$key );
|
||||
}
|
||||
|
||||
$attributes = $this->$key;
|
||||
|
||||
if ( is_array( $value ) ) {
|
||||
$attributes = array_merge( $attributes, $value );
|
||||
} else {
|
||||
$attributes[] = $value;
|
||||
}
|
||||
|
||||
$this->$key = array_unique( $attributes );
|
||||
|
||||
return $this->$key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the object has a key
|
||||
*
|
||||
* @param string $key The key to check.
|
||||
*
|
||||
* @return boolean True if the object has the key.
|
||||
*/
|
||||
public function has( $key ) {
|
||||
return property_exists( $this, $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert JSON input to an array.
|
||||
*
|
||||
* @param string $json The JSON string.
|
||||
*
|
||||
* @return static|\WP_Error An Object built from the JSON string or WP_Error when it's not a JSON string.
|
||||
*/
|
||||
public static function init_from_json( $json ) {
|
||||
$array = \json_decode( $json, true );
|
||||
|
||||
if ( ! is_array( $array ) ) {
|
||||
return new \WP_Error( 'invalid_json', __( 'Invalid JSON', 'activitypub' ), array( 'status' => 400 ) );
|
||||
}
|
||||
|
||||
return self::init_from_array( $array );
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert input array to a Base_Object.
|
||||
*
|
||||
* @param array $data The object array.
|
||||
*
|
||||
* @return static|\WP_Error An Object built from the input array or WP_Error when it's not an array.
|
||||
*/
|
||||
public static function init_from_array( $data ) {
|
||||
if ( ! is_array( $data ) ) {
|
||||
return new \WP_Error( 'invalid_array', __( 'Invalid array', 'activitypub' ), array( 'status' => 400 ) );
|
||||
}
|
||||
|
||||
$object = new static();
|
||||
$object->from_array( $data );
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert JSON input to an array and pre-fill the object.
|
||||
*
|
||||
* @param array $data The array.
|
||||
*/
|
||||
public function from_array( $data ) {
|
||||
foreach ( $data as $key => $value ) {
|
||||
if ( null !== $value ) {
|
||||
// Convert camelCase to snake_case if not prefixed with '_'.
|
||||
if ( ! \str_starts_with( $key, '_' ) ) {
|
||||
$key = camel_to_snake_case( $key );
|
||||
}
|
||||
|
||||
call_user_func( array( $this, 'set_' . $key ), $value );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert JSON input to an array and pre-fill the object.
|
||||
*
|
||||
* @param string $json The JSON string.
|
||||
*/
|
||||
public function from_json( $json ) {
|
||||
$array = \json_decode( $json, true );
|
||||
|
||||
$this->from_array( $array );
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Object to an array.
|
||||
*
|
||||
* It tries to get the object attributes if they exist
|
||||
* and falls back to the getters. Empty values are ignored.
|
||||
*
|
||||
* By default, `bto` and `bcc` (the blind audience fields) are stripped
|
||||
* from the output per ActivityPub Section 6, so every serialization path
|
||||
* is safe for emission. Internal callers that need to persist the blind
|
||||
* audience (e.g., outbox/inbox storage) can opt in by passing
|
||||
* `$include_blind_audience = true`.
|
||||
*
|
||||
* @param bool $include_json_ld_context Whether to include the JSON-LD context. Default true.
|
||||
* @param bool $include_blind_audience Whether to keep `bto` and `bcc` in the output. Default false.
|
||||
*
|
||||
* @return array An array built from the Object.
|
||||
*/
|
||||
public function to_array( $include_json_ld_context = true, $include_blind_audience = false ) {
|
||||
$array = array();
|
||||
$vars = get_object_vars( $this );
|
||||
|
||||
foreach ( $vars as $key => $value ) {
|
||||
if ( \is_wp_error( $value ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore all _prefixed keys.
|
||||
if ( '_' === substr( $key, 0, 1 ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If value is empty, try to get it from a getter.
|
||||
if ( ! $value ) {
|
||||
$value = call_user_func( array( $this, 'get_' . $key ) );
|
||||
}
|
||||
|
||||
if ( is_object( $value ) ) {
|
||||
$value = $value->to_array( false, $include_blind_audience );
|
||||
}
|
||||
|
||||
if ( is_array( $value ) && $this->is_namespaced( $key ) ) {
|
||||
foreach ( $value as $sub_key => $sub_value ) {
|
||||
$array[ snake_to_camel_case( $key ) . ':' . snake_to_camel_case( $sub_key ) ] = $sub_value;
|
||||
}
|
||||
} elseif ( isset( $value ) ) {
|
||||
$array[ snake_to_camel_case( $key ) ] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $include_json_ld_context ) {
|
||||
// Get JsonLD context and move it to '@context' at the top.
|
||||
$array = array_merge( array( '@context' => $this->get_json_ld_context() ), $array );
|
||||
}
|
||||
|
||||
$class = new \ReflectionClass( $this );
|
||||
$class = strtolower( $class->getShortName() );
|
||||
|
||||
/**
|
||||
* Filter the array of the ActivityPub object.
|
||||
*
|
||||
* @param array $array The array of the ActivityPub object.
|
||||
* @param string $class The class of the ActivityPub object.
|
||||
* @param string $id The ID of the ActivityPub object.
|
||||
* @param Generic_Object $object The ActivityPub object.
|
||||
*
|
||||
* @return array The filtered array of the ActivityPub object.
|
||||
*/
|
||||
$array = \apply_filters( 'activitypub_activity_object_array', $array, $class, $this->id, $this );
|
||||
|
||||
/**
|
||||
* Filter the array of the ActivityPub object by class.
|
||||
*
|
||||
* @param array $array The array of the ActivityPub object.
|
||||
* @param string $id The ID of the ActivityPub object.
|
||||
* @param Generic_Object $object The ActivityPub object.
|
||||
*
|
||||
* @return array The filtered array of the ActivityPub object.
|
||||
*/
|
||||
$array = \apply_filters( "activitypub_activity_{$class}_object_array", $array, $this->id, $this );
|
||||
|
||||
if ( ! $include_blind_audience ) {
|
||||
/*
|
||||
* Strip `bto` and `bcc` from the serialized array per ActivityPub Section 6.
|
||||
* Callers that need the blind audience either read it from the object via
|
||||
* `get_bto()` / `get_bcc()` or opt in with `$include_blind_audience = true`.
|
||||
*/
|
||||
unset( $array['bto'], $array['bcc'] );
|
||||
if ( isset( $array['object'] ) && \is_array( $array['object'] ) ) {
|
||||
unset( $array['object']['bto'], $array['object']['bcc'] );
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Object to JSON.
|
||||
*
|
||||
* @param bool $include_json_ld_context Whether to include the JSON-LD context. Default true.
|
||||
* @param bool $include_blind_audience Whether to keep `bto` and `bcc` in the output. Default false.
|
||||
*
|
||||
* @return string The JSON string.
|
||||
*/
|
||||
public function to_json( $include_json_ld_context = true, $include_blind_audience = false ) {
|
||||
$array = $this->to_array( $include_json_ld_context, $include_blind_audience );
|
||||
$options = \JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_QUOT | \JSON_UNESCAPED_SLASHES;
|
||||
|
||||
/**
|
||||
* Options to be passed to json_encode().
|
||||
*
|
||||
* @param int $options The current options flags.
|
||||
*/
|
||||
$options = \apply_filters( 'activitypub_json_encode_options', $options );
|
||||
|
||||
return \wp_json_encode( $array, $options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the keys of the object vars.
|
||||
*
|
||||
* @return array The keys of the object vars.
|
||||
*/
|
||||
public function get_object_var_keys() {
|
||||
return \array_keys( \get_object_vars( $this ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the JSON-LD context of this object.
|
||||
*
|
||||
* @return array $context A compacted JSON-LD context for the ActivityPub object.
|
||||
*/
|
||||
public function get_json_ld_context() {
|
||||
return static::JSON_LD_CONTEXT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an attribute is in a namespace.
|
||||
*
|
||||
* @param string $attribute The attribute to check.
|
||||
*
|
||||
* @return bool Whether the attribute is namespaced.
|
||||
*/
|
||||
private function is_namespaced( $attribute ) {
|
||||
$namespaces = array();
|
||||
|
||||
foreach ( static::JSON_LD_CONTEXT as $context ) {
|
||||
if ( is_array( $context ) ) {
|
||||
$namespaces = \array_merge( $namespaces, $context );
|
||||
}
|
||||
}
|
||||
|
||||
return isset( $namespaces[ $attribute ] ) && \wp_http_validate_url( $namespaces[ $attribute ] );
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
# Extended Objects
|
||||
|
||||
This folder contains more complex ActivityPub objects.
|
||||
|
||||
Although they could be created using the `Base_Object`, they provide an easier structure for creating objects with maximum compatibility.
|
||||
@ -0,0 +1,415 @@
|
||||
<?php
|
||||
/**
|
||||
* ActivityPub Object of type Event.
|
||||
*
|
||||
* @package activity-event-transformers
|
||||
*/
|
||||
|
||||
namespace Activitypub\Activity\Extended_Object;
|
||||
|
||||
use Activitypub\Activity\Base_Object;
|
||||
|
||||
/**
|
||||
* Event is an implementation of Activity Streams Event object type.
|
||||
*
|
||||
* This class contains extra keys as used by Mobilizon to ensure compatibility.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-event
|
||||
*
|
||||
* @method string|null get_actor() Gets which actor created the event.
|
||||
* @method float|null get_altitude() Gets the altitude of the event location.
|
||||
* @method bool|null get_anonymous_participation_enabled() Gets whether anonymous participation is enabled.
|
||||
* @method string|null get_category() Gets the event's category.
|
||||
* @method bool|null get_comments_enabled() Gets whether comments/replies are enabled.
|
||||
* @method array|null get_contacts() Gets the event's contacts.
|
||||
* @method string|null get_external_participation_url() Gets the external participation URL.
|
||||
* @method string|null get_in_language() Gets the language of the event.
|
||||
* @method bool|null get_is_online() Gets whether the event is online.
|
||||
* @method string|null get_join_mode() Gets how new members may be able to join.
|
||||
* @method int|null get_maximum_attendee_capacity() Gets how many places there can be for an event.
|
||||
* @method string|null get_name() Gets the title of the event.
|
||||
* @method int|null get_participant_count() Gets the participant count of the event.
|
||||
* @method int|null get_remaining_attendee_capacity() Gets the number of attendee places that remain unallocated.
|
||||
* @method string|null get_replies_moderation_option() Gets the moderation option for replies.
|
||||
* @method string|null get_status() Gets the event's status.
|
||||
* @method string|null get_timezone() Gets the timezone of the event.
|
||||
*
|
||||
* @method Event set_actor( string $actor ) Sets which actor created the event.
|
||||
* @method Event set_altitude( float $altitude ) Sets the altitude of the event location.
|
||||
* @method Event set_anonymous_participation_enabled( bool $enabled ) Sets whether anonymous participation is enabled.
|
||||
* @method Event set_category( string $category, bool $mobilizon_compatibility ) Sets the event's category.
|
||||
* @method Event set_comments_enabled( bool $comments_enabled ) Sets whether comments/replies are enabled.
|
||||
* @method Event set_contacts( array $contacts ) Sets the event's contacts.
|
||||
* @method Event set_external_participation_url( string $url ) Sets the external participation URL.
|
||||
* @method Event set_in_language( string $language ) Sets the language of the event.
|
||||
* @method Event set_is_online( bool $is_online ) Sets whether the event is online.
|
||||
* @method Event set_join_mode( string $join_mode ) Sets how new members may be able to join.
|
||||
* @method Event set_maximum_attendee_capacity( int $capacity ) Sets how many places there can be for an event.
|
||||
* @method Event set_name( string $name ) Sets the title of the event.
|
||||
* @method Event set_participant_count( int $count ) Sets the participant count of the event.
|
||||
* @method Event set_remaining_attendee_capacity( int $capacity ) Sets the number of attendee places that remain unallocated.
|
||||
* @method Event set_replies_moderation_option( string $type ) Sets the moderation option for replies.
|
||||
* @method Event set_status( string $status ) Sets the event's status.
|
||||
* @method Event set_timezone( string $timezone ) Sets the timezone of the event.
|
||||
*/
|
||||
class Event extends Base_Object {
|
||||
// Human friendly minimal context for full Mobilizon compatible ActivityPub events.
|
||||
const JSON_LD_CONTEXT = array(
|
||||
'https://schema.org/', // The base context is schema.org, because it is used a lot.
|
||||
'https://www.w3.org/ns/activitystreams', // The ActivityStreams context overrides everything also defined in schema.org.
|
||||
array( // The keys here override/extend the context even more.
|
||||
'pt' => 'https://joinpeertube.org/ns#',
|
||||
'mz' => 'https://joinmobilizon.org/ns#',
|
||||
'status' => 'http://www.w3.org/2002/12/cal/ical#status',
|
||||
'commentsEnabled' => 'pt:commentsEnabled',
|
||||
'isOnline' => 'mz:isOnline',
|
||||
'timezone' => 'mz:timezone',
|
||||
'participantCount' => 'mz:participantCount',
|
||||
'anonymousParticipationEnabled' => 'mz:anonymousParticipationEnabled',
|
||||
'joinMode' => array(
|
||||
'@id' => 'mz:joinMode',
|
||||
'@type' => 'mz:joinModeType',
|
||||
),
|
||||
'externalParticipationUrl' => array(
|
||||
'@id' => 'mz:externalParticipationUrl',
|
||||
'@type' => 'schema:URL',
|
||||
),
|
||||
'repliesModerationOption' => array(
|
||||
'@id' => 'mz:repliesModerationOption',
|
||||
'@type' => '@vocab',
|
||||
),
|
||||
'contacts' => array(
|
||||
'@id' => 'mz:contacts',
|
||||
'@type' => '@id',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Mobilizon compatible values for repliesModerationOption.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
const REPLIES_MODERATION_OPTION_TYPES = array( 'allow_all', 'closed' );
|
||||
|
||||
/**
|
||||
* Mobilizon compatible values for joinModeTypes.
|
||||
*/
|
||||
const JOIN_MODE_TYPES = array( 'free', 'restricted', 'external' ); // and 'invite', but not used by mobilizon atm.
|
||||
|
||||
/**
|
||||
* Allowed values for ical VEVENT STATUS.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
const ICAL_EVENT_STATUS_TYPES = array( 'TENTATIVE', 'CONFIRMED', 'CANCELLED' );
|
||||
|
||||
/**
|
||||
* Default event categories.
|
||||
*
|
||||
* These values currently reflect the default set as proposed by Mobilizon to maximize interoperability.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
const DEFAULT_EVENT_CATEGORIES = array(
|
||||
'ARTS',
|
||||
'BOOK_CLUBS',
|
||||
'BUSINESS',
|
||||
'CAUSES',
|
||||
'COMEDY',
|
||||
'CRAFTS',
|
||||
'FOOD_DRINK',
|
||||
'HEALTH',
|
||||
'MUSIC',
|
||||
'AUTO_BOAT_AIR',
|
||||
'COMMUNITY',
|
||||
'FAMILY_EDUCATION',
|
||||
'FASHION_BEAUTY',
|
||||
'FILM_MEDIA',
|
||||
'GAMES',
|
||||
'LANGUAGE_CULTURE',
|
||||
'LEARNING',
|
||||
'LGBTQ',
|
||||
'MOVEMENTS_POLITICS',
|
||||
'NETWORKING',
|
||||
'PARTY',
|
||||
'PERFORMING_VISUAL_ARTS',
|
||||
'PETS',
|
||||
'PHOTOGRAPHY',
|
||||
'OUTDOORS_ADVENTURE',
|
||||
'SPIRITUALITY_RELIGION_BELIEFS',
|
||||
'SCIENCE_TECH',
|
||||
'SPORTS',
|
||||
'THEATRE',
|
||||
'MEETING', // Default value.
|
||||
);
|
||||
|
||||
/**
|
||||
* Event is an implementation of one of the Activity Streams.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $type = 'Event';
|
||||
|
||||
/**
|
||||
* The Title of the event.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* The event's contacts.
|
||||
*
|
||||
* @context {
|
||||
* '@id' => 'mz:contacts',
|
||||
* '@type' => '@id',
|
||||
* }
|
||||
*
|
||||
* @var array Array of contacts (ActivityPub actor IDs).
|
||||
*/
|
||||
protected $contacts;
|
||||
|
||||
/**
|
||||
* Extension invented by PeerTube whether comments/replies are <enabled>
|
||||
* Mobilizon also implemented this as a fallback to their own
|
||||
* repliesModerationOption.
|
||||
*
|
||||
* @see https://docs.joinpeertube.org/api/activitypub#video
|
||||
* @see https://docs.joinmobilizon.org/contribute/activity_pub/
|
||||
* @var bool|null
|
||||
*/
|
||||
protected $comments_enabled;
|
||||
|
||||
/**
|
||||
* Timezone of the event.
|
||||
*
|
||||
* @context https://joinmobilizon.org/ns#timezone
|
||||
* @var string
|
||||
*/
|
||||
protected $timezone;
|
||||
|
||||
/**
|
||||
* Moderation option for replies.
|
||||
*
|
||||
* @context https://joinmobilizon.org/ns#repliesModerationOption
|
||||
* @see https://docs.joinmobilizon.org/contribute/activity_pub/#repliesmoderation
|
||||
* @var string
|
||||
*/
|
||||
protected $replies_moderation_option;
|
||||
|
||||
/**
|
||||
* Whether anonymous participation is enabled.
|
||||
*
|
||||
* @context https://joinmobilizon.org/ns#anonymousParticipationEnabled
|
||||
* @see https://docs.joinmobilizon.org/contribute/activity_pub/#anonymousparticipationenabled
|
||||
* @var bool
|
||||
*/
|
||||
protected $anonymous_participation_enabled;
|
||||
|
||||
/**
|
||||
* The event's category.
|
||||
*
|
||||
* @context https://schema.org/category
|
||||
* @var string
|
||||
*/
|
||||
protected $category;
|
||||
|
||||
/**
|
||||
* Language of the event.
|
||||
*
|
||||
* @context https://schema.org/inLanguage
|
||||
* @var string
|
||||
*/
|
||||
protected $in_language;
|
||||
|
||||
/**
|
||||
* Whether the event is online.
|
||||
*
|
||||
* @context https://joinmobilizon.org/ns#isOnline
|
||||
* @var bool
|
||||
*/
|
||||
protected $is_online;
|
||||
|
||||
/**
|
||||
* The event's status.
|
||||
*
|
||||
* @context https://www.w3.org/2002/12/cal/ical#status
|
||||
* @var string
|
||||
*/
|
||||
protected $status;
|
||||
|
||||
/**
|
||||
* Which actor created the event.
|
||||
*
|
||||
* This field is needed due to the current group structure of Mobilizon.
|
||||
*
|
||||
* @todo this seems to not be a default property of an Object but needed by mobilizon.
|
||||
* @var string
|
||||
*/
|
||||
protected $actor;
|
||||
|
||||
/**
|
||||
* The external participation URL.
|
||||
*
|
||||
* @context https://joinmobilizon.org/ns#externalParticipationUrl
|
||||
* @var string
|
||||
*/
|
||||
protected $external_participation_url;
|
||||
|
||||
/**
|
||||
* Indicator of how new members may be able to join.
|
||||
*
|
||||
* @context https://joinmobilizon.org/ns#joinMode
|
||||
* @see https://docs.joinmobilizon.org/contribute/activity_pub/#joinmode
|
||||
* @var string
|
||||
*/
|
||||
protected $join_mode;
|
||||
|
||||
/**
|
||||
* The participant count of the event.
|
||||
*
|
||||
* @context https://joinmobilizon.org/ns#participantCount
|
||||
* @var int
|
||||
*/
|
||||
protected $participant_count;
|
||||
|
||||
/**
|
||||
* How many places there can be for an event.
|
||||
*
|
||||
* @context https://schema.org/maximumAttendeeCapacity
|
||||
* @see https://docs.joinmobilizon.org/contribute/activity_pub/#maximumattendeecapacity
|
||||
* @var int
|
||||
*/
|
||||
protected $maximum_attendee_capacity;
|
||||
|
||||
/**
|
||||
* The number of attendee places for an event that remain unallocated.
|
||||
*
|
||||
* @context https://schema.org/remainingAttendeeCapacity
|
||||
* @see https://docs.joinmobilizon.org/contribute/activity_pub/#remainignattendeecapacity
|
||||
* @var int
|
||||
*/
|
||||
protected $remaining_attendee_capacity;
|
||||
|
||||
/**
|
||||
* Setter for the timezone.
|
||||
*
|
||||
* The passed timezone is only set when it is a valid one, otherwise the site's timezone is used.
|
||||
*
|
||||
* @param string $timezone The timezone string to be set, e.g. 'Europe/Berlin'.
|
||||
* @return Event
|
||||
*/
|
||||
public function set_timezone( $timezone ) {
|
||||
if ( in_array( $timezone, timezone_identifiers_list(), true ) ) {
|
||||
$this->timezone = $timezone;
|
||||
} else {
|
||||
$this->timezone = wp_timezone_string();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom setter for repliesModerationOption which also directly sets commentsEnabled accordingly.
|
||||
*
|
||||
* @param string $type The type of the replies moderation option.
|
||||
*
|
||||
* @return Event
|
||||
*/
|
||||
public function set_replies_moderation_option( $type ) {
|
||||
if ( in_array( $type, self::REPLIES_MODERATION_OPTION_TYPES, true ) ) {
|
||||
$this->replies_moderation_option = $type;
|
||||
$this->comments_enabled = ( 'allow_all' === $type ) ? true : false;
|
||||
} else {
|
||||
_doing_it_wrong(
|
||||
__METHOD__,
|
||||
'The replies moderation option must be either allow_all or closed.',
|
||||
'<version_placeholder>'
|
||||
);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom setter for commentsEnabled which also directly sets repliesModerationOption accordingly.
|
||||
*
|
||||
* @param bool $comments_enabled Whether comments are enabled.
|
||||
*
|
||||
* @return Event
|
||||
*/
|
||||
public function set_comments_enabled( $comments_enabled ) {
|
||||
if ( is_bool( $comments_enabled ) ) {
|
||||
$this->comments_enabled = $comments_enabled;
|
||||
$this->replies_moderation_option = $comments_enabled ? 'allow_all' : 'closed';
|
||||
} else {
|
||||
_doing_it_wrong(
|
||||
__METHOD__,
|
||||
'The commentsEnabled must be boolean.',
|
||||
'<version_placeholder>'
|
||||
);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom setter for the ical status that checks whether the status is an ical event status.
|
||||
*
|
||||
* @param string $status The status of the event.
|
||||
*
|
||||
* @return Event
|
||||
*/
|
||||
public function set_status( $status ) {
|
||||
if ( in_array( $status, self::ICAL_EVENT_STATUS_TYPES, true ) ) {
|
||||
$this->status = $status;
|
||||
} else {
|
||||
_doing_it_wrong(
|
||||
__METHOD__,
|
||||
'The status of the event must be a VEVENT iCal status.',
|
||||
'<version_placeholder>'
|
||||
);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom setter for the event category.
|
||||
*
|
||||
* Falls back to Mobilizon's default category.
|
||||
*
|
||||
* @param string $category The category of the event.
|
||||
* @param bool $mobilizon_compatibility Optional. Whether the category must be compatibly with Mobilizon. Default true.
|
||||
*
|
||||
* @return Event
|
||||
*/
|
||||
public function set_category( $category, $mobilizon_compatibility = true ) {
|
||||
if ( $mobilizon_compatibility ) {
|
||||
$this->category = in_array( $category, self::DEFAULT_EVENT_CATEGORIES, true ) ? $category : 'MEETING';
|
||||
} else {
|
||||
$this->category = $category;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom setter for an external participation url.
|
||||
*
|
||||
* Automatically sets the joinMode to true if called.
|
||||
*
|
||||
* @param string $url The URL for external participation.
|
||||
*
|
||||
* @return Event
|
||||
*/
|
||||
public function set_external_participation_url( $url ) {
|
||||
if ( preg_match( '/^https?:\/\/.*/i', $url ) ) {
|
||||
$this->external_participation_url = $url;
|
||||
$this->join_mode = 'external';
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/**
|
||||
* Event is an implementation of one of the
|
||||
* Activity Streams Event object type
|
||||
*
|
||||
* @package activity-event-transformers
|
||||
*/
|
||||
|
||||
namespace Activitypub\Activity\Extended_Object;
|
||||
|
||||
use Activitypub\Activity\Base_Object;
|
||||
|
||||
/**
|
||||
* Place is an implementation of the Activity Streams Place object type.
|
||||
*
|
||||
* The Place object represents a logical or physical location.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-place
|
||||
*
|
||||
* @method float|null get_accuracy() Gets the accuracy of position coordinates.
|
||||
* @method array|string|null get_address() Gets the address of the place.
|
||||
* @method float|null get_altitude() Gets the altitude of the place.
|
||||
* @method float|null get_latitude() Gets the latitude of the place.
|
||||
* @method float|null get_longitude() Gets the longitude of the place.
|
||||
* @method float|null get_radius() Gets the radius from the given latitude and longitude.
|
||||
* @method string|null get_units() Gets the measurement units for radius and altitude.
|
||||
*
|
||||
* @method Place set_accuracy( float $accuracy ) Sets the accuracy of position coordinates.
|
||||
* @method Place set_address( array|string $address ) Sets the address of the place.
|
||||
* @method Place set_altitude( float $altitude ) Sets the altitude of the place.
|
||||
* @method Place set_latitude( float $latitude ) Sets the latitude of the place.
|
||||
* @method Place set_longitude( float $longitude ) Sets the longitude of the place.
|
||||
* @method Place set_radius( float $radius ) Sets the radius from the given latitude and longitude.
|
||||
* @method Place set_units( string $units ) Sets the measurement units for radius and altitude.
|
||||
*/
|
||||
class Place extends Base_Object {
|
||||
/**
|
||||
* Place is an implementation of one of the
|
||||
* Activity Streams
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $type = 'Place';
|
||||
|
||||
/**
|
||||
* Indicates the accuracy of position coordinates on a Place objects.
|
||||
* Expressed in properties of percentage. e.g. "94.0" means "94.0% accurate".
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-accuracy
|
||||
* @var float xsd:float [>= 0.0f, <= 100.0f]
|
||||
*/
|
||||
protected $accuracy;
|
||||
|
||||
/**
|
||||
* Indicates the altitude of a place. The measurement unit is indicated using the unit's property.
|
||||
* If unit is not specified, the default is assumed to be "m" indicating meters.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-altitude
|
||||
* @var float xsd:float
|
||||
*/
|
||||
protected $altitude;
|
||||
|
||||
/**
|
||||
* The latitude of a place.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-latitude
|
||||
* @var float xsd:float
|
||||
*/
|
||||
protected $latitude;
|
||||
|
||||
/**
|
||||
* The longitude of a place.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-longitude
|
||||
* @var float xsd:float
|
||||
*/
|
||||
protected $longitude;
|
||||
|
||||
/**
|
||||
* The radius from the given latitude and longitude for a Place.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-radius
|
||||
* @var float
|
||||
*/
|
||||
protected $radius;
|
||||
|
||||
/**
|
||||
* Specifies the measurement units for the `radius` and `altitude` properties.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-units
|
||||
* @var string
|
||||
*/
|
||||
protected $units;
|
||||
|
||||
/**
|
||||
* The address of the place.
|
||||
*
|
||||
* @see https://schema.org/PostalAddress
|
||||
* @var array|string
|
||||
*/
|
||||
protected $address;
|
||||
|
||||
/**
|
||||
* Set the address of the place.
|
||||
*
|
||||
* @param array|string $address The address of the place.
|
||||
*/
|
||||
public function set_address( $address ) {
|
||||
if ( is_string( $address ) || is_array( $address ) ) {
|
||||
$this->address = $address;
|
||||
} else {
|
||||
_doing_it_wrong(
|
||||
__METHOD__,
|
||||
'The address must be either a string or an array like schema.org/PostalAddress.',
|
||||
'<version_placeholder>'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* Quote_Authorization is an implementation of the QuoteAuthorization activity type,
|
||||
* as defined in FEP-044f (https://codeberg.org/fediverse/fep/src/branch/main/fep/044f/fep-044f.md#quoteauthorization).
|
||||
*
|
||||
* This class represents a QuoteAuthorization activity for ActivityPub implementations.
|
||||
*
|
||||
* @package Activitypub
|
||||
*/
|
||||
|
||||
namespace Activitypub\Activity\Extended_Object;
|
||||
|
||||
use Activitypub\Activity\Base_Object;
|
||||
|
||||
/**
|
||||
* Class representing a QuoteAuthorization activity.
|
||||
*
|
||||
* @see https://codeberg.org/fediverse/fep/src/branch/main/fep/044f/fep-044f.md#quoteauthorization
|
||||
*
|
||||
* @since 7.5.0
|
||||
*
|
||||
* @method Base_Object|string|array|null get_interacting_object() Gets the interacting object property of the object.
|
||||
* @method Base_Object|string|array|null get_interaction_target() Gets the interaction target property of the object.
|
||||
*
|
||||
* @method Quote_Authorization set_interacting_object( string|array|Base_Object|null $data ) Sets the interacting object property of the object.
|
||||
* @method Quote_Authorization set_interaction_target( string|array|Base_Object|null $data ) Sets the interaction target property of the object.
|
||||
*/
|
||||
class Quote_Authorization extends Base_Object {
|
||||
/**
|
||||
* The JSON-LD context for the object.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
const JSON_LD_CONTEXT = array(
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
array(
|
||||
'QuoteAuthorization' => 'https://w3id.org/fep/044f#QuoteAuthorization',
|
||||
'gts' => 'https://gotosocial.org/ns#',
|
||||
'interactingObject' => array(
|
||||
'@id' => 'gts:interactingObject',
|
||||
'@type' => '@id',
|
||||
),
|
||||
'interactionTarget' => array(
|
||||
'@id' => 'gts:interactionTarget',
|
||||
'@type' => '@id',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* The type of the object.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $type = 'QuoteAuthorization';
|
||||
|
||||
/**
|
||||
* The object that is being interacted with.
|
||||
*
|
||||
* @var Base_Object|string|array|null
|
||||
*/
|
||||
protected $interacting_object;
|
||||
|
||||
/**
|
||||
* The target of the interaction.
|
||||
*
|
||||
* @var Base_Object|string|array|null
|
||||
*/
|
||||
protected $interaction_target;
|
||||
}
|
||||
Reference in New Issue
Block a user