PluginProbe
ActivityPub / 3.2.2
ActivityPub v3.2.2
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 3.2.2, at includes/activity/class-activity.php

196 lines 5.0 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 JSON_LD_CONTEXT = array(
21 'https://www.w3.org/ns/activitystreams',
22 );
23
24 /**
25 * @var string
26 */
27 protected $type = 'Activity';
28
29 /**
30 * Describes the direct object of the activity.
31 * For instance, in the activity "John added a movie to his
32 * wishlist", the object of the activity is the movie added.
33 *
34 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-object-term
35 *
36 * @var string
37 * | Base_Object
38 * | Link
39 * | null
40 */
41 protected $object;
42
43 /**
44 * Describes one or more entities that either performed or are
45 * expected to perform the activity.
46 * Any single activity can have multiple actors.
47 * The actor MAY be specified using an indirect Link.
48 *
49 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-actor
50 *
51 * @var string
52 * | \ActivityPhp\Type\Extended\AbstractActor
53 * | array<Actor>
54 * | array<Link>
55 * | Link
56 */
57 protected $actor;
58
59 /**
60 * The indirect object, or target, of the activity.
61 * The precise meaning of the target is largely dependent on the
62 * type of action being described but will often be the object of
63 * the English preposition "to".
64 * For instance, in the activity "John added a movie to his
65 * wishlist", the target of the activity is John's wishlist.
66 * An activity can have more than one target.
67 *
68 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-target
69 *
70 * @var string
71 * | ObjectType
72 * | array<ObjectType>
73 * | Link
74 * | array<Link>
75 */
76 protected $target;
77
78 /**
79 * Describes the result of the activity.
80 * For instance, if a particular action results in the creation of
81 * a new resource, the result property can be used to describe
82 * that new resource.
83 *
84 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-result
85 *
86 * @var string
87 * | ObjectType
88 * | Link
89 * | null
90 */
91 protected $result;
92
93 /**
94 * An indirect object of the activity from which the
95 * activity is directed.
96 * The precise meaning of the origin is the object of the English
97 * preposition "from".
98 * For instance, in the activity "John moved an item to List B
99 * from List A", the origin of the activity is "List A".
100 *
101 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-origin
102 *
103 * @var string
104 * | ObjectType
105 * | Link
106 * | null
107 */
108 protected $origin;
109
110 /**
111 * One or more objects used (or to be used) in the completion of an
112 * Activity.
113 *
114 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-instrument
115 *
116 * @var string
117 * | ObjectType
118 * | Link
119 * | null
120 */
121 protected $instrument;
122
123 /**
124 * Set the object and copy Object properties to the Activity.
125 *
126 * Any to, bto, cc, bcc, and audience properties specified on the object
127 * MUST be copied over to the new Create activity by the server.
128 *
129 * @see https://www.w3.org/TR/activitypub/#object-without-create
130 *
131 * @param string|Base_Objectr|Link|null $object
132 *
133 * @return void
134 */
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
142 $this->set( 'object', $object );
143
144 if ( ! is_object( $object ) ) {
145 return;
146 }
147
148 foreach ( array( 'to', 'bto', 'cc', 'bcc', 'audience' ) as $i ) {
149 $this->set( $i, $object->get( $i ) );
150 }
151
152 if ( $object->get_published() && ! $this->get_published() ) {
153 $this->set( 'published', $object->get_published() );
154 }
155
156 if ( $object->get_updated() && ! $this->get_updated() ) {
157 $this->set( 'updated', $object->get_updated() );
158 }
159
160 if ( $object->get_attributed_to() && ! $this->get_actor() ) {
161 $this->set( 'actor', $object->get_attributed_to() );
162 }
163
164 if ( $object->get_in_reply_to() ) {
165 $this->set( 'in_reply_to', $object->get_in_reply_to() );
166 }
167
168 if ( $object->get_id() && ! $this->get_id() ) {
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 );
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;
194 }
195 }
196