PluginProbe
ActivityPub / 7.0.0
ActivityPub v7.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 / extended-object / class-event.php

class-event.php in ActivityPub 7.0.0, at includes/activity/extended-object/class-event.php

380 lines 9.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ActivityPub Object of type Event.
4 *
5 * @package activity-event-transformers
6 */
7
8 namespace Activitypub\Activity\Extended_Object;
9
10 use Activitypub\Activity\Base_Object;
11
12 /**
13 * Event is an implementation of one of the Activity Streams Event object type.
14 *
15 * This class contains extra keys as used by Mobilizon to ensure compatibility.
16 *
17 * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-event
18 */
19 class Event extends Base_Object {
20 // Human friendly minimal context for full Mobilizon compatible ActivityPub events.
21 const JSON_LD_CONTEXT = array(
22 'https://schema.org/', // The base context is schema.org, because it is used a lot.
23 'https://www.w3.org/ns/activitystreams', // The ActivityStreams context overrides everything also defined in schema.org.
24 array( // The keys here override/extend the context even more.
25 'pt' => 'https://joinpeertube.org/ns#',
26 'mz' => 'https://joinmobilizon.org/ns#',
27 'status' => 'http://www.w3.org/2002/12/cal/ical#status',
28 'commentsEnabled' => 'pt:commentsEnabled',
29 'isOnline' => 'mz:isOnline',
30 'timezone' => 'mz:timezone',
31 'participantCount' => 'mz:participantCount',
32 'anonymousParticipationEnabled' => 'mz:anonymousParticipationEnabled',
33 'joinMode' => array(
34 '@id' => 'mz:joinMode',
35 '@type' => 'mz:joinModeType',
36 ),
37 'externalParticipationUrl' => array(
38 '@id' => 'mz:externalParticipationUrl',
39 '@type' => 'schema:URL',
40 ),
41 'repliesModerationOption' => array(
42 '@id' => 'mz:repliesModerationOption',
43 '@type' => '@vocab',
44 ),
45 'contacts' => array(
46 '@id' => 'mz:contacts',
47 '@type' => '@id',
48 ),
49 ),
50 );
51
52 /**
53 * Mobilizon compatible values for repliesModerationOption.
54 *
55 * @var array
56 */
57 const REPLIES_MODERATION_OPTION_TYPES = array( 'allow_all', 'closed' );
58
59 /**
60 * Mobilizon compatible values for joinModeTypes.
61 */
62 const JOIN_MODE_TYPES = array( 'free', 'restricted', 'external' ); // and 'invite', but not used by mobilizon atm.
63
64 /**
65 * Allowed values for ical VEVENT STATUS.
66 *
67 * @var array
68 */
69 const ICAL_EVENT_STATUS_TYPES = array( 'TENTATIVE', 'CONFIRMED', 'CANCELLED' );
70
71 /**
72 * Default event categories.
73 *
74 * These values currently reflect the default set as proposed by Mobilizon to maximize interoperability.
75 *
76 * @var array
77 */
78 const DEFAULT_EVENT_CATEGORIES = array(
79 'ARTS',
80 'BOOK_CLUBS',
81 'BUSINESS',
82 'CAUSES',
83 'COMEDY',
84 'CRAFTS',
85 'FOOD_DRINK',
86 'HEALTH',
87 'MUSIC',
88 'AUTO_BOAT_AIR',
89 'COMMUNITY',
90 'FAMILY_EDUCATION',
91 'FASHION_BEAUTY',
92 'FILM_MEDIA',
93 'GAMES',
94 'LANGUAGE_CULTURE',
95 'LEARNING',
96 'LGBTQ',
97 'MOVEMENTS_POLITICS',
98 'NETWORKING',
99 'PARTY',
100 'PERFORMING_VISUAL_ARTS',
101 'PETS',
102 'PHOTOGRAPHY',
103 'OUTDOORS_ADVENTURE',
104 'SPIRITUALITY_RELIGION_BELIEFS',
105 'SCIENCE_TECH',
106 'SPORTS',
107 'THEATRE',
108 'MEETING', // Default value.
109 );
110
111 /**
112 * Event is an implementation of one of the Activity Streams.
113 *
114 * @var string
115 */
116 protected $type = 'Event';
117
118 /**
119 * The Title of the event.
120 *
121 * @var string
122 */
123 protected $name;
124
125 /**
126 * The event's contacts.
127 *
128 * @context {
129 * '@id' => 'mz:contacts',
130 * '@type' => '@id',
131 * }
132 *
133 * @var array Array of contacts (ActivityPub actor IDs).
134 */
135 protected $contacts;
136
137 /**
138 * Extension invented by PeerTube whether comments/replies are <enabled>
139 * Mobilizon also implemented this as a fallback to their own
140 * repliesModerationOption.
141 *
142 * @see https://docs.joinpeertube.org/api/activitypub#video
143 * @see https://docs.joinmobilizon.org/contribute/activity_pub/
144 * @var bool|null
145 */
146 protected $comments_enabled;
147
148 /**
149 * Timezone of the event.
150 *
151 * @context https://joinmobilizon.org/ns#timezone
152 * @var string
153 */
154 protected $timezone;
155
156 /**
157 * Moderation option for replies.
158 *
159 * @context https://joinmobilizon.org/ns#repliesModerationOption
160 * @see https://docs.joinmobilizon.org/contribute/activity_pub/#repliesmoderation
161 * @var string
162 */
163 protected $replies_moderation_option;
164
165 /**
166 * Whether anonymous participation is enabled.
167 *
168 * @context https://joinmobilizon.org/ns#anonymousParticipationEnabled
169 * @see https://docs.joinmobilizon.org/contribute/activity_pub/#anonymousparticipationenabled
170 * @var bool
171 */
172 protected $anonymous_participation_enabled;
173
174 /**
175 * The event's category.
176 *
177 * @context https://schema.org/category
178 * @var string
179 */
180 protected $category;
181
182 /**
183 * Language of the event.
184 *
185 * @context https://schema.org/inLanguage
186 * @var string
187 */
188 protected $in_language;
189
190 /**
191 * Whether the event is online.
192 *
193 * @context https://joinmobilizon.org/ns#isOnline
194 * @var bool
195 */
196 protected $is_online;
197
198 /**
199 * The event's status.
200 *
201 * @context https://www.w3.org/2002/12/cal/ical#status
202 * @var string
203 */
204 protected $status;
205
206 /**
207 * Which actor created the event.
208 *
209 * This field is needed due to the current group structure of Mobilizon.
210 *
211 * @todo this seems to not be a default property of an Object but needed by mobilizon.
212 * @var string
213 */
214 protected $actor;
215
216 /**
217 * The external participation URL.
218 *
219 * @context https://joinmobilizon.org/ns#externalParticipationUrl
220 * @var string
221 */
222 protected $external_participation_url;
223
224 /**
225 * Indicator of how new members may be able to join.
226 *
227 * @context https://joinmobilizon.org/ns#joinMode
228 * @see https://docs.joinmobilizon.org/contribute/activity_pub/#joinmode
229 * @var string
230 */
231 protected $join_mode;
232
233 /**
234 * The participant count of the event.
235 *
236 * @context https://joinmobilizon.org/ns#participantCount
237 * @var int
238 */
239 protected $participant_count;
240
241 /**
242 * How many places there can be for an event.
243 *
244 * @context https://schema.org/maximumAttendeeCapacity
245 * @see https://docs.joinmobilizon.org/contribute/activity_pub/#maximumattendeecapacity
246 * @var int
247 */
248 protected $maximum_attendee_capacity;
249
250 /**
251 * The number of attendee places for an event that remain unallocated.
252 *
253 * @context https://schema.org/remainingAttendeeCapacity
254 * @see https://docs.joinmobilizon.org/contribute/activity_pub/#remainignattendeecapacity
255 * @var int
256 */
257 protected $remaining_attendee_capacity;
258
259 /**
260 * Setter for the timezone.
261 *
262 * The passed timezone is only set when it is a valid one, otherwise the site's timezone is used.
263 *
264 * @param string $timezone The timezone string to be set, e.g. 'Europe/Berlin'.
265 * @return Event
266 */
267 public function set_timezone( $timezone ) {
268 if ( in_array( $timezone, timezone_identifiers_list(), true ) ) {
269 $this->timezone = $timezone;
270 } else {
271 $this->timezone = wp_timezone_string();
272 }
273
274 return $this;
275 }
276
277 /**
278 * Custom setter for repliesModerationOption which also directly sets commentsEnabled accordingly.
279 *
280 * @param string $type The type of the replies moderation option.
281 *
282 * @return Event
283 */
284 public function set_replies_moderation_option( $type ) {
285 if ( in_array( $type, self::REPLIES_MODERATION_OPTION_TYPES, true ) ) {
286 $this->replies_moderation_option = $type;
287 $this->comments_enabled = ( 'allow_all' === $type ) ? true : false;
288 } else {
289 _doing_it_wrong(
290 __METHOD__,
291 'The replies moderation option must be either allow_all or closed.',
292 '<version_placeholder>'
293 );
294 }
295
296 return $this;
297 }
298
299 /**
300 * Custom setter for commentsEnabled which also directly sets repliesModerationOption accordingly.
301 *
302 * @param bool $comments_enabled Whether comments are enabled.
303 *
304 * @return Event
305 */
306 public function set_comments_enabled( $comments_enabled ) {
307 if ( is_bool( $comments_enabled ) ) {
308 $this->comments_enabled = $comments_enabled;
309 $this->replies_moderation_option = $comments_enabled ? 'allow_all' : 'closed';
310 } else {
311 _doing_it_wrong(
312 __METHOD__,
313 'The commentsEnabled must be boolean.',
314 '<version_placeholder>'
315 );
316 }
317
318 return $this;
319 }
320
321 /**
322 * Custom setter for the ical status that checks whether the status is an ical event status.
323 *
324 * @param string $status The status of the event.
325 *
326 * @return Event
327 */
328 public function set_status( $status ) {
329 if ( in_array( $status, self::ICAL_EVENT_STATUS_TYPES, true ) ) {
330 $this->status = $status;
331 } else {
332 _doing_it_wrong(
333 __METHOD__,
334 'The status of the event must be a VEVENT iCal status.',
335 '<version_placeholder>'
336 );
337 }
338
339 return $this;
340 }
341
342 /**
343 * Custom setter for the event category.
344 *
345 * Falls back to Mobilizon's default category.
346 *
347 * @param string $category The category of the event.
348 * @param bool $mobilizon_compatibility Optional. Whether the category must be compatibly with Mobilizon. Default true.
349 *
350 * @return Event
351 */
352 public function set_category( $category, $mobilizon_compatibility = true ) {
353 if ( $mobilizon_compatibility ) {
354 $this->category = in_array( $category, self::DEFAULT_EVENT_CATEGORIES, true ) ? $category : 'MEETING';
355 } else {
356 $this->category = $category;
357 }
358
359 return $this;
360 }
361
362 /**
363 * Custom setter for an external participation url.
364 *
365 * Automatically sets the joinMode to true if called.
366 *
367 * @param string $url The URL for external participation.
368 *
369 * @return Event
370 */
371 public function set_external_participation_url( $url ) {
372 if ( preg_match( '/^https?:\/\/.*/i', $url ) ) {
373 $this->external_participation_url = $url;
374 $this->join_mode = 'external';
375 }
376
377 return $this;
378 }
379 }
380