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

217 lines 5.5 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 'value' => 'schema:value',
32 'Hashtag' => 'as:Hashtag',
33 'featured' => array(
34 '@id' => 'toot:featured',
35 '@type' => '@id',
36 ),
37 'featuredTags' => array(
38 '@id' => 'toot:featuredTags',
39 '@type' => '@id',
40 ),
41 'alsoKnownAs' => array(
42 '@id' => 'as:alsoKnownAs',
43 '@type' => '@id',
44 ),
45 'discoverable' => 'toot:discoverable',
46 'sensitive' => 'as:sensitive',
47 'resource' => 'webfinger:resource',
48 ),
49 );
50
51 /**
52 * The object's unique global identifier
53 *
54 * @see https://www.w3.org/TR/activitypub/#obj-id
55 *
56 * @var string
57 */
58 protected $id;
59
60 /**
61 * @var string
62 */
63 protected $type = 'Activity';
64
65 /**
66 * The context within which the object exists or an activity was
67 * performed.
68 * The notion of "context" used is intentionally vague.
69 * The intended function is to serve as a means of grouping objects
70 * and activities that share a common originating context or
71 * purpose. An example could be all activities relating to a common
72 * project or event.
73 *
74 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-context
75 *
76 * @var string
77 * | ObjectType
78 * | Link
79 * | null
80 */
81 protected $context = self::CONTEXT;
82
83 /**
84 * Describes the direct object of the activity.
85 * For instance, in the activity "John added a movie to his
86 * wishlist", the object of the activity is the movie added.
87 *
88 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-object-term
89 *
90 * @var string
91 * | Base_Objectr
92 * | Link
93 * | null
94 */
95 protected $object;
96
97 /**
98 * Describes one or more entities that either performed or are
99 * expected to perform the activity.
100 * Any single activity can have multiple actors.
101 * The actor MAY be specified using an indirect Link.
102 *
103 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-actor
104 *
105 * @var string
106 * | \ActivityPhp\Type\Extended\AbstractActor
107 * | array<Actor>
108 * | array<Link>
109 * | Link
110 */
111 protected $actor;
112
113 /**
114 * The indirect object, or target, of the activity.
115 * The precise meaning of the target is largely dependent on the
116 * type of action being described but will often be the object of
117 * the English preposition "to".
118 * For instance, in the activity "John added a movie to his
119 * wishlist", the target of the activity is John's wishlist.
120 * An activity can have more than one target.
121 *
122 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-target
123 *
124 * @var string
125 * | ObjectType
126 * | array<ObjectType>
127 * | Link
128 * | array<Link>
129 */
130 protected $target;
131
132 /**
133 * Describes the result of the activity.
134 * For instance, if a particular action results in the creation of
135 * a new resource, the result property can be used to describe
136 * that new resource.
137 *
138 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-result
139 *
140 * @var string
141 * | ObjectType
142 * | Link
143 * | null
144 */
145 protected $result;
146
147 /**
148 * An indirect object of the activity from which the
149 * activity is directed.
150 * The precise meaning of the origin is the object of the English
151 * preposition "from".
152 * For instance, in the activity "John moved an item to List B
153 * from List A", the origin of the activity is "List A".
154 *
155 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-origin
156 *
157 * @var string
158 * | ObjectType
159 * | Link
160 * | null
161 */
162 protected $origin;
163
164 /**
165 * One or more objects used (or to be used) in the completion of an
166 * Activity.
167 *
168 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-instrument
169 *
170 * @var string
171 * | ObjectType
172 * | Link
173 * | null
174 */
175 protected $instrument;
176
177 /**
178 * Set the object and copy Object properties to the Activity.
179 *
180 * Any to, bto, cc, bcc, and audience properties specified on the object
181 * MUST be copied over to the new Create activity by the server.
182 *
183 * @see https://www.w3.org/TR/activitypub/#object-without-create
184 *
185 * @param string|Base_Objectr|Link|null $object
186 *
187 * @return void
188 */
189 public function set_object( $object ) {
190 $this->set( 'object', $object );
191
192 if ( ! is_object( $object ) ) {
193 return;
194 }
195
196 foreach ( array( 'to', 'bto', 'cc', 'bcc', 'audience' ) as $i ) {
197 $this->set( $i, $object->get( $i ) );
198 }
199
200 if ( $object->get_published() && ! $this->get_published() ) {
201 $this->set( 'published', $object->get_published() );
202 }
203
204 if ( $object->get_updated() && ! $this->get_updated() ) {
205 $this->set( 'updated', $object->get_updated() );
206 }
207
208 if ( $object->get_attributed_to() && ! $this->get_actor() ) {
209 $this->set( 'actor', $object->get_attributed_to() );
210 }
211
212 if ( $object->get_id() && ! $this->get_id() ) {
213 $this->set( 'id', $object->get_id() . '#activity' );
214 }
215 }
216 }
217