PluginProbe
ActivityPub / 3.2.5
ActivityPub v3.2.5
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
← All changes | includes/activity/class-activity.php +36 -64 1.0.53.2.5 View file →
@@ -16,79 +16,18 @@
16 16 * @see https://www.w3.org/TR/activitystreams-core/#activities
17 17 * @see https://www.w3.org/TR/activitystreams-core/#intransitiveactivities
18 18 */
19 19 class Activity extends Base_Object {
20 - const CONTEXT = array(
20 + const JSON_LD_CONTEXT = array(
21 21 'https://www.w3.org/ns/activitystreams',
22 - 'https://w3id.org/security/v1',
23 - array(
24 - 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
25 - 'PropertyValue' => 'schema:PropertyValue',
26 - 'schema' => 'http://schema.org#',
27 - 'pt' => 'https://joinpeertube.org/ns#',
28 - 'toot' => 'http://joinmastodon.org/ns#',
29 - 'webfinger' => 'https://webfinger.net/#',
30 - 'litepub' => 'http://litepub.social/ns#',
31 - 'lemmy' => 'https://join-lemmy.org/ns#',
32 - 'value' => 'schema:value',
33 - 'Hashtag' => 'as:Hashtag',
34 - 'featured' => array(
35 - '@id' => 'toot:featured',
36 - '@type' => '@id',
37 - ),
38 - 'featuredTags' => array(
39 - '@id' => 'toot:featuredTags',
40 - '@type' => '@id',
41 - ),
42 - 'alsoKnownAs' => array(
43 - '@id' => 'as:alsoKnownAs',
44 - '@type' => '@id',
45 - ),
46 - 'moderators' => array(
47 - '@id' => 'lemmy:moderators',
48 - '@type' => '@id',
49 - ),
50 - 'postingRestrictedToMods' => 'lemmy:postingRestrictedToMods',
51 - 'discoverable' => 'toot:discoverable',
52 - 'indexable' => 'toot:indexable',
53 - 'sensitive' => 'as:sensitive',
54 - 'resource' => 'webfinger:resource',
55 - ),
56 22 );
57 23
58 24 /**
59 - * The object's unique global identifier
60 - *
61 - * @see https://www.w3.org/TR/activitypub/#obj-id
62 - *
63 25 * @var string
64 26 */
65 - protected $id;
66 -
67 - /**
68 - * @var string
69 - */
70 27 protected $type = 'Activity';
71 28
72 29 /**
73 - * The context within which the object exists or an activity was
74 - * performed.
75 - * The notion of "context" used is intentionally vague.
76 - * The intended function is to serve as a means of grouping objects
77 - * and activities that share a common originating context or
78 - * purpose. An example could be all activities relating to a common
79 - * project or event.
80 - *
81 - * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-context
82 - *
83 - * @var string
84 - * | ObjectType
85 - * | Link
86 - * | null
87 - */
88 - protected $context = self::CONTEXT;
89 -
90 - /**
91 30 * Describes the direct object of the activity.
92 31 * For instance, in the activity "John added a movie to his
93 32 * wishlist", the object of the activity is the movie added.
94 33 *
@@ -94,9 +33,9 @@
94 33 *
95 34 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-object-term
96 35 *
97 36 * @var string
98 - * | Base_Objectr
37 + * | Base_Object
99 38 * | Link
100 39 * | null
101 40 */
102 41 protected $object;
@@ -193,8 +132,14 @@
193 132 *
194 133 * @return void
195 134 */
196 135 public function set_object( $object ) {
136 + // convert array to object
137 + if ( is_array( $object ) ) {
138 + $object = self::init_from_array( $object );
139 + }
140 +
141 + // set object
197 142 $this->set( 'object', $object );
198 143
199 144 if ( ! is_object( $object ) ) {
200 145 return;
@@ -215,9 +160,36 @@
215 160 if ( $object->get_attributed_to() && ! $this->get_actor() ) {
216 161 $this->set( 'actor', $object->get_attributed_to() );
217 162 }
218 163
164 + if ( $object->get_in_reply_to() ) {
165 + $this->set( 'in_reply_to', $object->get_in_reply_to() );
166 + }
167 +
219 168 if ( $object->get_id() && ! $this->get_id() ) {
220 - $this->set( 'id', $object->get_id() . '#activity' );
169 + $id = strtok( $object->get_id(), '#' );
170 + if ( $object->get_updated() ) {
171 + $updated = $object->get_updated();
172 + } else {
173 + $updated = $object->get_published();
174 + }
175 + $this->set( 'id', $id . '#activity-' . strtolower( $this->get_type() ) . '-' . $updated );
221 176 }
177 + }
178 +
179 + /**
180 + * The context of an Activity is usually just the context of the object it contains.
181 + *
182 + * @return array $context A compacted JSON-LD context.
183 + */
184 + public function get_json_ld_context() {
185 + if ( $this->object instanceof Base_Object ) {
186 + $class = get_class( $this->object );
187 + if ( $class && $class::JSON_LD_CONTEXT ) {
188 + // Without php 5.6 support this could be just: 'return $this->object::JSON_LD_CONTEXT;'
189 + return $class::JSON_LD_CONTEXT;
190 + }
191 + }
192 +
193 + return static::JSON_LD_CONTEXT;
222 194 }
223 195 }