PluginProbe
ActivityPub / 3.2.4
ActivityPub v3.2.4
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 3.2.4, at includes/activity/extended-object/class-event.php

341 lines 8.5 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, cause it is used a lot.
23 'https://www.w3.org/ns/activitystreams', // The ActivityStreams context overrides everyting 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 repliesModertaionOption.
54 * @var array
55 */
56 const REPLIES_MODERATION_OPTION_TYPES = array( 'allow_all', 'closed' );
57
58 /**
59 * Mobilizon compatible values for joinModeTypes.
60 */
61 const JOIN_MODE_TYPES = array( 'free', 'restricted', 'external' ); // and 'invite', but not used by mobilizon atm
62
63 /**
64 * Allowed values for ical VEVENT STATUS.
65 * @var array
66 */
67 const ICAL_EVENT_STATUS_TYPES = array( 'TENTATIVE', 'CONFIRMED', 'CANCELLED' );
68
69 /**
70 * Default event categories.
71 *
72 * These values currently reflect the default set as proposed by Mobilizon to maximize interoperability.
73 * @var array
74 */
75 const DEFAULT_EVENT_CATEGORIES = array(
76 'ARTS',
77 'BOOK_CLUBS',
78 'BUSINESS',
79 'CAUSES',
80 'COMEDY',
81 'CRAFTS',
82 'FOOD_DRINK',
83 'HEALTH',
84 'MUSIC',
85 'AUTO_BOAT_AIR',
86 'COMMUNITY',
87 'FAMILY_EDUCATION',
88 'FASHION_BEAUTY',
89 'FILM_MEDIA',
90 'GAMES',
91 'LANGUAGE_CULTURE',
92 'LEARNING',
93 'LGBTQ',
94 'MOVEMENTS_POLITICS',
95 'NETWORKING',
96 'PARTY',
97 'PERFORMING_VISUAL_ARTS',
98 'PETS',
99 'PHOTOGRAPHY',
100 'OUTDOORS_ADVENTURE',
101 'SPIRITUALITY_RELIGION_BELIEFS',
102 'SCIENCE_TECH',
103 'SPORTS',
104 'THEATRE',
105 'MEETING', // Default value.
106 );
107
108 /**
109 * Event is an implementation of one of the
110 * Activity Streams
111 *
112 * @var string
113 */
114 protected $type = 'Event';
115
116 /**
117 * The Title of the event.
118 */
119 protected $name;
120
121 /**
122 * The events contacts
123 *
124 * @context {
125 * '@id' => 'mz:contacts',
126 * '@type' => '@id',
127 * }
128 *
129 * @var array Array of contacts (ActivityPub actor IDs).
130 */
131 protected $contacts;
132
133 /**
134 * Extension invented by PeerTube whether comments/replies are <enabled>
135 * Mobilizon also implemented this as a fallback to their own
136 * repliesModerationOption.
137 *
138 * @see https://docs.joinpeertube.org/api/activitypub#video
139 * @see https://docs.joinmobilizon.org/contribute/activity_pub/
140 * @var bool|null
141 */
142 protected $comments_enabled;
143
144 /**
145 * @context https://joinmobilizon.org/ns#timezone
146 * @var string
147 */
148 protected $timezone;
149
150 /**
151 * @context https://joinmobilizon.org/ns#repliesModerationOption
152 * @see https://docs.joinmobilizon.org/contribute/activity_pub/#repliesmoderation
153 * @var string
154 */
155 protected $replies_moderation_option;
156
157 /**
158 * @context https://joinmobilizon.org/ns#anonymousParticipationEnabled
159 * @see https://docs.joinmobilizon.org/contribute/activity_pub/#anonymousparticipationenabled
160 * @var bool
161 */
162 protected $anonymous_participation_enabled;
163
164 /**
165 * @context https://schema.org/category
166 * @var enum
167 */
168 protected $category;
169
170 /**
171 * @context https://schema.org/inLanguage
172 * @var
173 */
174 protected $in_language;
175
176 /**
177 * @context https://joinmobilizon.org/ns#isOnline
178 * @var bool
179 */
180 protected $is_online;
181
182 /**
183 * @context https://www.w3.org/2002/12/cal/ical#status
184 * @var enum
185 */
186 protected $status;
187
188 /**
189 * Which actor created the event.
190 *
191 * This field is needed due to the current group structure of Mobilizon.
192 *
193 * @todo this seems to not be a default property of an Object but needed by mobilizon.
194 * @var string
195 */
196 protected $actor;
197
198 /**
199 * @context https://joinmobilizon.org/ns#externalParticipationUrl
200 * @var string
201 */
202 protected $external_participation_url;
203
204 /**
205 * @context https://joinmobilizon.org/ns#joinMode
206 * @see https://docs.joinmobilizon.org/contribute/activity_pub/#joinmode
207 * @var
208 */
209 protected $join_mode;
210
211 /**
212 * @context https://joinmobilizon.org/ns#participantCount
213 * @var int
214 */
215 protected $participant_count;
216
217 /**
218 * @context https://schema.org/maximumAttendeeCapacity
219 * @see https://docs.joinmobilizon.org/contribute/activity_pub/#maximumattendeecapacity
220 * @var int
221 */
222 protected $maximum_attendee_capacity;
223
224 /**
225 * @context https://schema.org/remainingAttendeeCapacity
226 * @see https://docs.joinmobilizon.org/contribute/activity_pub/#remainignattendeecapacity
227 * @var int
228 */
229 protected $remaining_attendee_capacity;
230
231 /**
232 * Setter for the timezone.
233 *
234 * The passed timezone is only set when it is a valid one, otherwise the site's timezone is used.
235 *
236 * @param string $timezone The timezone string to be set, e.g. 'Europe/Berlin'.
237 */
238 public function set_timezone( $timezone ) {
239 if ( in_array( $timezone, timezone_identifiers_list(), true ) ) {
240 $this->timezone = $timezone;
241 } else {
242 $this->timezone = wp_timezone_string();
243 }
244
245 return $this;
246 }
247
248 /**
249 * Custom setter for repliesModerationOption which also directy sets commentsEnabled accordingly.
250 *
251 * @param string $type
252 */
253 public function set_replies_moderation_option( $type ) {
254 if ( in_array( $type, self::REPLIES_MODERATION_OPTION_TYPES, true ) ) {
255 $this->replies_moderation_option = $type;
256 $this->comments_enabled = ( 'allow_all' === $type ) ? true : false;
257 } else {
258 _doing_it_wrong(
259 __METHOD__,
260 'The replies moderation option must be either allow_all or closed.',
261 '<version_placeholder>'
262 );
263 }
264
265 return $this;
266 }
267
268 /**
269 * Custom setter for commentsEnabled which also directly sets repliesModerationOption accordingly.
270 *
271 * @param bool $comments_enabled
272 */
273 public function set_comments_enabled( $comments_enabled ) {
274 if ( is_bool( $comments_enabled ) ) {
275 $this->comments_enabled = $comments_enabled;
276 $this->replies_moderation_option = $comments_enabled ? 'allow_all' : 'closed';
277 } else {
278 _doing_it_wrong(
279 __METHOD__,
280 'The commentsEnabled must be boolean.',
281 '<version_placeholder>'
282 );
283 }
284
285 return $this;
286 }
287
288 /**
289 * Custom setter for the ical status that checks whether the status is an ical event status.
290 *
291 * @param string $status
292 */
293 public function set_status( $status ) {
294 if ( in_array( $status, self::ICAL_EVENT_STATUS_TYPES, true ) ) {
295 $this->status = $status;
296 } else {
297 _doing_it_wrong(
298 __METHOD__,
299 'The status of the event must be a VEVENT iCal status.',
300 '<version_placeholder>'
301 );
302 }
303
304 return $this;
305 }
306
307 /**
308 * Custom setter for the event category.
309 *
310 * Falls back to Mobilizons default category.
311 *
312 * @param string $category
313 * @param bool $mobilizon_compatibilty Whether the category must be compatibly with Mobilizon.
314 */
315 public function set_category( $category, $mobilizon_compatibilty = true ) {
316 if ( $mobilizon_compatibilty ) {
317 $this->category = in_array( $category, self::DEFAULT_EVENT_CATEGORIES, true ) ? $category : 'MEETING';
318 } else {
319 $this->category = $category;
320 }
321
322 return $this;
323 }
324
325 /**
326 * Custom setter for an external participation url.
327 *
328 * Automatically sets the joinMode to true if called.
329 *
330 * @param string $url
331 */
332 public function set_external_participation_url( $url ) {
333 if ( preg_match( '/^https?:\/\/.*/i', $url ) ) {
334 $this->external_participation_url = $url;
335 $this->join_mode = 'external';
336 }
337
338 return $this;
339 }
340 }
341