PluginProbe
ActivityPub / 2.0.0
ActivityPub v2.0.0
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
activitypub / includes / activity / class-activity.php

class-activity.php in ActivityPub 2.0.0, at includes/activity/class-activity.php

229 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Inspired by the PHP ActivityPub Library by @Landrok
4 *
5 * @link https://github.com/landrok/activitypub
6 */
7
8 namespace Activitypub\Activity;
9
10 use Activitypub\Activity\Base_Object;
11
12 /**
13 * \Activitypub\Activity\Activity implements the common
14 * attributes of an Activity.
15 *
16 * @see https://www.w3.org/TR/activitystreams-core/#activities
17 * @see https://www.w3.org/TR/activitystreams-core/#intransitiveactivities
18 */
19 class Activity extends Base_Object {
20 const CONTEXT = array(
21 'https://www.w3.org/ns/activitystreams',
22 'https://w3id.org/security/v1',
23 'https://purl.archive.org/socialweb/webfinger',
24 array(
25 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
26 'PropertyValue' => 'schema:PropertyValue',
27 'schema' => 'http://schema.org#',
28 'pt' => 'https://joinpeertube.org/ns#',
29 'toot' => 'http://joinmastodon.org/ns#',
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 ),
55 );
56
57 /**
58 * The object's unique global identifier
59 *
60 * @see https://www.w3.org/TR/activitypub/#obj-id
61 *
62 * @var string
63 */
64 protected $id;
65
66 /**
67 * @var string
68 */
69 protected $type = 'Activity';
70
71 /**
72 * The context within which the object exists or an activity was
73 * performed.
74 * The notion of "context" used is intentionally vague.
75 * The intended function is to serve as a means of grouping objects
76 * and activities that share a common originating context or
77 * purpose. An example could be all activities relating to a common
78 * project or event.
79 *
80 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-context
81 *
82 * @var string
83 * | ObjectType
84 * | Link
85 * | null
86 */
87 protected $context = self::CONTEXT;
88
89 /**
90 * Describes the direct object of the activity.
91 * For instance, in the activity "John added a movie to his
92 * wishlist", the object of the activity is the movie added.
93 *
94 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-object-term
95 *
96 * @var string
97 * | Base_Objectr
98 * | Link
99 * | null
100 */
101 protected $object;
102
103 /**
104 * Describes one or more entities that either performed or are
105 * expected to perform the activity.
106 * Any single activity can have multiple actors.
107 * The actor MAY be specified using an indirect Link.
108 *
109 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-actor
110 *
111 * @var string
112 * | \ActivityPhp\Type\Extended\AbstractActor
113 * | array<Actor>
114 * | array<Link>
115 * | Link
116 */
117 protected $actor;
118
119 /**
120 * The indirect object, or target, of the activity.
121 * The precise meaning of the target is largely dependent on the
122 * type of action being described but will often be the object of
123 * the English preposition "to".
124 * For instance, in the activity "John added a movie to his
125 * wishlist", the target of the activity is John's wishlist.
126 * An activity can have more than one target.
127 *
128 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-target
129 *
130 * @var string
131 * | ObjectType
132 * | array<ObjectType>
133 * | Link
134 * | array<Link>
135 */
136 protected $target;
137
138 /**
139 * Describes the result of the activity.
140 * For instance, if a particular action results in the creation of
141 * a new resource, the result property can be used to describe
142 * that new resource.
143 *
144 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-result
145 *
146 * @var string
147 * | ObjectType
148 * | Link
149 * | null
150 */
151 protected $result;
152
153 /**
154 * An indirect object of the activity from which the
155 * activity is directed.
156 * The precise meaning of the origin is the object of the English
157 * preposition "from".
158 * For instance, in the activity "John moved an item to List B
159 * from List A", the origin of the activity is "List A".
160 *
161 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-origin
162 *
163 * @var string
164 * | ObjectType
165 * | Link
166 * | null
167 */
168 protected $origin;
169
170 /**
171 * One or more objects used (or to be used) in the completion of an
172 * Activity.
173 *
174 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-instrument
175 *
176 * @var string
177 * | ObjectType
178 * | Link
179 * | null
180 */
181 protected $instrument;
182
183 /**
184 * Set the object and copy Object properties to the Activity.
185 *
186 * Any to, bto, cc, bcc, and audience properties specified on the object
187 * MUST be copied over to the new Create activity by the server.
188 *
189 * @see https://www.w3.org/TR/activitypub/#object-without-create
190 *
191 * @param string|Base_Objectr|Link|null $object
192 *
193 * @return void
194 */
195 public function set_object( $object ) {
196 // convert array to object
197 if ( is_array( $object ) ) {
198 $object = self::init_from_array( $object );
199 }
200
201 // set object
202 $this->set( 'object', $object );
203
204 if ( ! is_object( $object ) ) {
205 return;
206 }
207
208 foreach ( array( 'to', 'bto', 'cc', 'bcc', 'audience' ) as $i ) {
209 $this->set( $i, $object->get( $i ) );
210 }
211
212 if ( $object->get_published() && ! $this->get_published() ) {
213 $this->set( 'published', $object->get_published() );
214 }
215
216 if ( $object->get_updated() && ! $this->get_updated() ) {
217 $this->set( 'updated', $object->get_updated() );
218 }
219
220 if ( $object->get_attributed_to() && ! $this->get_actor() ) {
221 $this->set( 'actor', $object->get_attributed_to() );
222 }
223
224 if ( $object->get_id() && ! $this->get_id() ) {
225 $this->set( 'id', $object->get_id() . '#activity' );
226 }
227 }
228 }
229