PluginProbe
ActivityPub / 1.0.9
ActivityPub v1.0.9
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 1.0.9, at includes/activity/class-activity.php

224 lines 5.8 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 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 );
57
58 /**
59 * The object's unique global identifier
60 *
61 * @see https://www.w3.org/TR/activitypub/#obj-id
62 *
63 * @var string
64 */
65 protected $id;
66
67 /**
68 * @var string
69 */
70 protected $type = 'Activity';
71
72 /**
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 * Describes the direct object of the activity.
92 * For instance, in the activity "John added a movie to his
93 * wishlist", the object of the activity is the movie added.
94 *
95 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-object-term
96 *
97 * @var string
98 * | Base_Objectr
99 * | Link
100 * | null
101 */
102 protected $object;
103
104 /**
105 * Describes one or more entities that either performed or are
106 * expected to perform the activity.
107 * Any single activity can have multiple actors.
108 * The actor MAY be specified using an indirect Link.
109 *
110 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-actor
111 *
112 * @var string
113 * | \ActivityPhp\Type\Extended\AbstractActor
114 * | array<Actor>
115 * | array<Link>
116 * | Link
117 */
118 protected $actor;
119
120 /**
121 * The indirect object, or target, of the activity.
122 * The precise meaning of the target is largely dependent on the
123 * type of action being described but will often be the object of
124 * the English preposition "to".
125 * For instance, in the activity "John added a movie to his
126 * wishlist", the target of the activity is John's wishlist.
127 * An activity can have more than one target.
128 *
129 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-target
130 *
131 * @var string
132 * | ObjectType
133 * | array<ObjectType>
134 * | Link
135 * | array<Link>
136 */
137 protected $target;
138
139 /**
140 * Describes the result of the activity.
141 * For instance, if a particular action results in the creation of
142 * a new resource, the result property can be used to describe
143 * that new resource.
144 *
145 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-result
146 *
147 * @var string
148 * | ObjectType
149 * | Link
150 * | null
151 */
152 protected $result;
153
154 /**
155 * An indirect object of the activity from which the
156 * activity is directed.
157 * The precise meaning of the origin is the object of the English
158 * preposition "from".
159 * For instance, in the activity "John moved an item to List B
160 * from List A", the origin of the activity is "List A".
161 *
162 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-origin
163 *
164 * @var string
165 * | ObjectType
166 * | Link
167 * | null
168 */
169 protected $origin;
170
171 /**
172 * One or more objects used (or to be used) in the completion of an
173 * Activity.
174 *
175 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-instrument
176 *
177 * @var string
178 * | ObjectType
179 * | Link
180 * | null
181 */
182 protected $instrument;
183
184 /**
185 * Set the object and copy Object properties to the Activity.
186 *
187 * Any to, bto, cc, bcc, and audience properties specified on the object
188 * MUST be copied over to the new Create activity by the server.
189 *
190 * @see https://www.w3.org/TR/activitypub/#object-without-create
191 *
192 * @param string|Base_Objectr|Link|null $object
193 *
194 * @return void
195 */
196 public function set_object( $object ) {
197 $this->set( 'object', $object );
198
199 if ( ! is_object( $object ) ) {
200 return;
201 }
202
203 foreach ( array( 'to', 'bto', 'cc', 'bcc', 'audience' ) as $i ) {
204 $this->set( $i, $object->get( $i ) );
205 }
206
207 if ( $object->get_published() && ! $this->get_published() ) {
208 $this->set( 'published', $object->get_published() );
209 }
210
211 if ( $object->get_updated() && ! $this->get_updated() ) {
212 $this->set( 'updated', $object->get_updated() );
213 }
214
215 if ( $object->get_attributed_to() && ! $this->get_actor() ) {
216 $this->set( 'actor', $object->get_attributed_to() );
217 }
218
219 if ( $object->get_id() && ! $this->get_id() ) {
220 $this->set( 'id', $object->get_id() . '#activity' );
221 }
222 }
223 }
224