forked from bootscore/bootscore-child
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshortcode-functions.php
425 lines (358 loc) · 17.4 KB
/
shortcode-functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
<?php
// Get the Engage Functions
get_template_part('engage-functions', '');
// Homepage Events Shortcode
// Display the three closest upcoming events. For use on the homepage.
function home_events_function()
{
// Get the Engage API Key
$engage_api_key = get_option('engage_api_key');
// If the Engage API Key is null or does not exist
if ($engage_api_key == NULL || $engage_api_key == false) {
if (current_user_can('manage_options')) {
$error = '<div class="alert alert-danger">';
$error .= 'You must set the Engage API Key under Settings -> Engage/Event Settings to display events on the homepage.';
$error .= '</div>';
} else {
$error = '<div class="alert alert-danger">';
$error .= 'An error has occurred. <a href="/contact">Contact our team.</a>';
$error .= '</div>';
}
return $error;
}
// Get the CUP Organization ID
$cup_org_id = get_option('engage_cup_org_id');
// If the CUP Organization ID is null or does not exist
if ($cup_org_id == NULL || $cup_org_id == false) {
if (current_user_can('manage_options')) {
$error = '<div class="alert alert-danger">';
$error .= 'You must set the CUP Organization ID under Settings -> Engage/Event Settings to display events.';
$error .= '</div>';
} else {
$error = '<div class="alert alert-danger">';
$error .= 'An error has occurred. <a href="/contact">Contact our team.</a>';
$error .= '</div>';
}
return $error;
}
// Make the request for upcoming events
$request = engage_request_cached('homepage_events', 300, '/events/event/', array(
'organizationIds' => $cup_org_id,
'endsAfter' => utcTimestamp(),
'excludeCoHosts' => 'false',
'includeSubmissionIds' => 'true'
));
// Seperate the returned item subarray from the total items value
$items = $request['items'];
$totalItems = intval($request['totalItems']);
// Sort the returned events by start date/time
usort($items, function ($a, $b) {
if ($a['startsOn'] == $b['startsOn']) return 0;
return strtotime($a['startsOn']) - strtotime($b['startsOn']);
});
// Keep only the first three events in the array
if ($totalItems > 3) {
$items = array_slice($items, 0, 3);
$totalItems = 3;
}
// Start HTML variable
$html = '';
// Show an alert if no upcoming events are scheduled, or show events
if ($totalItems <= 0) {
$html .= '<div class="events home-events">';
$html .= '<div class="alert alert-info no-events">';
$html .= 'There are no scheduled upcoming events just yet. Stay tuned!';
$html .= '</div></div>';
} elseif ($totalItems > 0) {
// Start events row
$html .= '<div class="events home-events row g-3">';
// code for each item (column)
foreach ($items as $item) {
// Convert start time format
$eventStartTimeObject = new DateTimeImmutable($item['startsOn'], new DateTimeZone('UTC'));
$eventStartTimeEST = $eventStartTimeObject->setTimezone(new DateTimeZone('America/New_York'));
$eventStartTimeString = $eventStartTimeEST->format('l, F j \a\t g\:iA T');
// event wrapper HTML
$html .= '<div class="event-wrapper col-12 col-md-4">';
$html .= '<div class="card border-dark event-card">';
// event image if there is one
if (strlen($item['imageUrl']) > 0) {
$html .= '<a href="https://neu.campuslabs.com/engage/event/' . $item['id'] . '" class="event-img-link" target="_blank">';
$html .= '<div role="img" aria-label="Image Uploaded for Event Cover Photo" alt ="Image Uploaded for Event Cover Photo" class="card-img-top event-img border-bottom border-dark" style="background-image: url(\'' . $item['imageUrl'] . '?preset=large-w\');">';
$html .= '</div></a>';
}
// event body
$html .= '<div class="card-body event-body">';
// event title
$html .= '<a href="https://neu.campuslabs.com/engage/event/' . $item['id'] . '" class="event-title-link" target="_blank">';
$html .= '<h3 class="card-title event-title">' . $item['name'];
$html .= '</h3></a>';
// event text
$html .= '<div class="card-text event-text">';
// event date
$html .= '<div class="event-date pb-1">';
$html .= '<span class="bi bi-pe-1 bi-calendar2-heart">' . $eventStartTimeString;
$html .= '</span></div>';
// event location
$html .= '<div class="event-location pb-3">';
$html .= '<span class="bi bi-pe-1 bi-geo-alt-fill">' . $item['address']['name'];
$html .= '</span></div>';
// event button
$html .= '<div class="event-button">';
$html .= '<a href="https://neu.campuslabs.com/engage/event/' . $item['id'] . '" class="btn btn-primary bi bi-pe-2 bi-box-arrow-up-right" target="_blank">';
$html .= 'Learn More';
$html .= '</a></div>';
// closing tags for event text, body, card, and wrapper
$html .= '</div></div></div></div>';
}
// row closing tag
$html .= '</div>';
}
// return the html
return $html;
}
add_shortcode('home_events', 'home_events_function');
// Upcoming Events Shortcode
// Display cards for all upcoming events.
function upcoming_events_function()
{
// Get the Engage API Key
$engage_api_key = get_option('engage_api_key');
// If the Engage API Key is null or does not exist
if ($engage_api_key == NULL || $engage_api_key == false) {
if (current_user_can('manage_options')) {
$error = '<div class="alert alert-danger">';
$error .= 'You must set the Engage API Key under Settings -> Engage/Event Settings to display upcoming events.';
$error .= '</div>';
} else {
$error = '<div class="alert alert-danger">';
$error .= 'An error has occurred. <a href="/contact">Contact our team.</a>';
$error .= '</div>';
}
return $error;
}
// Get the CUP Organization ID
$cup_org_id = get_option('engage_cup_org_id');
// If the CUP Organization ID is null or does not exist
if ($cup_org_id == NULL || $cup_org_id == false) {
if (current_user_can('manage_options')) {
$error = '<div class="alert alert-danger">';
$error .= 'You must set the CUP Organization ID under Settings -> Engage/Event Settings to display events.';
$error .= '</div>';
} else {
$error = '<div class="alert alert-danger">';
$error .= 'An error has occurred. <a href="/contact">Contact our team.</a>';
$error .= '</div>';
}
return $error;
}
// Make the request for upcoming events
$request = engage_request_concat_cached('upcoming_events', 300, '/events/event/', array(
'organizationIds' => $cup_org_id,
'endsAfter' => utcTimestamp(),
'excludeCoHosts' => 'false',
'includeSubmissionIds' => 'true'
));
// Seperate the returned item subarray from the total items value
$items = $request['items'];
$totalItems = intval($request['totalItems']);
// Sort the returned events by start date/time
usort($items, function ($a, $b) {
if ($a['startsOn'] == $b['startsOn']) return 0;
return strtotime($a['startsOn']) - strtotime($b['startsOn']);
});
// Split the array of events into chunks of 3
$items = array_chunk($items, 3);
// Start HTML variable
$html = '';
// Show an alert if no upcoming events are scheduled, or show events
if ($totalItems <= 0) {
$html .= '<div class="events upcoming-events">';
$html .= '<div class="alert alert-info no-events">';
$html .= 'There are no scheduled upcoming events just yet. Stay tuned!';
$html .= '</div></div>';
} elseif ($totalItems > 0) {
// All upcoming events wrapper
$html .= '<div class="events upcoming-events">';
// Cycle through each row
foreach ($items as $row) {
// Start new row
$html .= '<div class="event-row row g-3 pb-3">';
foreach ($row as $event) {
// Convert start time format
$eventStartTimeObject = new DateTimeImmutable($event['startsOn'], new DateTimeZone('UTC'));
$eventStartTimeEST = $eventStartTimeObject->setTimezone(new DateTimeZone('America/New_York'));
$eventStartTimeString = $eventStartTimeEST->format('l, F j \a\t g\:iA T');
// event wrapper HTML
$html .= '<div class="event-wrapper col-12 col-md-4">';
$html .= '<div class="card border-dark event-card">';
// event image if there is one
if (strlen($event['imageUrl']) > 0) {
$html .= '<a href="https://neu.campuslabs.com/engage/event/' . $event['id'] . '" class="event-img-link" target="_blank">';
$html .= '<div role="img" aria-label="Image Uploaded for Event Cover Photo" alt ="Image Uploaded for Event Cover Photo" class="card-img-top event-img border-bottom border-dark" style="background-image: url(\'' . $event['imageUrl'] . '?preset=large-w\');">';
$html .= '</div></a>';
}
// event body
$html .= '<div class="card-body event-body">';
// event title
$html .= '<a href="https://neu.campuslabs.com/engage/event/' . $event['id'] . '" class="event-title-link" target="_blank">';
$html .= '<h3 class="card-title event-title">' . $event['name'];
$html .= '</h3></a>';
// event text
$html .= '<div class="card-text event-text">';
// event date
$html .= '<div class="event-date pb-1">';
$html .= '<span class="bi bi-pe-1 bi-calendar2-heart">' . $eventStartTimeString;
$html .= '</span></div>';
// event location
$html .= '<div class="event-location pb-3">';
$html .= '<span class="bi bi-pe-1 bi-geo-alt-fill">' . $event['address']['name'];
$html .= '</span></div>';
// event button
$html .= '<div class="event-button">';
$html .= '<a href="https://neu.campuslabs.com/engage/event/' . $event['id'] . '" class="btn btn-primary bi bi-pe-2 bi-box-arrow-up-right" target="_blank">';
$html .= 'Learn More';
$html .= '</a></div>';
// closing tags for event text, body, card, and wrapper
$html .= '</div></div></div></div>';
}
// Row closing tag
$html .= '</div>';
}
// All events closing tag
$html .= '</div>';
}
// return the html
return $html;
}
add_shortcode('upcoming_events', 'upcoming_events_function');
// Past Events Shortcode
// Display cards for all past events.
function past_events_function()
{
// Get the Engage API Key
$engage_api_key = get_option('engage_api_key');
// If the Engage API Key is null or does not exist
if ($engage_api_key == NULL || $engage_api_key == false) {
if (current_user_can('manage_options')) {
$error = '<div class="alert alert-danger">';
$error .= 'You must set the Engage API Key under Settings -> Engage/Event Settings to display past events.';
$error .= '</div>';
} else {
$error = '<div class="alert alert-danger">';
$error .= 'An error has occurred. <a href="/contact">Contact our team.</a>';
$error .= '</div>';
}
return $error;
}
// Get the CUP Organization ID
$cup_org_id = get_option('engage_cup_org_id');
// If the CUP Organization ID is null or does not exist
if ($cup_org_id == NULL || $cup_org_id == false) {
if (current_user_can('manage_options')) {
$error = '<div class="alert alert-danger">';
$error .= 'You must set the CUP Organization ID under Settings -> Engage/Event Settings to display events.';
$error .= '</div>';
} else {
$error = '<div class="alert alert-danger">';
$error .= 'An error has occurred. <a href="/contact">Contact our team.</a>';
$error .= '</div>';
}
return $error;
}
// Get the event cutoff date
$event_cutoff = get_option('engage_event_cutoff');
// If the event cutoff date is null or does not exist
if ($event_cutoff == NULL || $event_cutoff == false) {
if (current_user_can('manage_options')) {
$error = '<div class="alert alert-danger">';
$error .= 'You must set the past event cutoff date under Settings -> Engage/Event Settings to display past events.';
$error .= '</div>';
} else {
$error = '<div class="alert alert-danger">';
$error .= 'An error has occurred. <a href="/contact">Contact our team.</a>';
$error .= '</div>';
}
return $error;
}
// Make the request for upcoming events
$request = engage_request_concat_cached('past_events', 300, '/events/event/', array(
'organizationIds' => $cup_org_id,
'endsBefore' => utcTimestamp(),
'startsAfter' => $event_cutoff,
'excludeCoHosts' => 'false',
'includeSubmissionIds' => 'true'
));
// Seperate the returned item subarray from the total items value
$items = $request['items'];
$totalItems = intval($request['totalItems']);
// Sort the returned events in descending order by start date/time
usort($items, function ($a, $b) {
if ($b['startsOn'] == $a['startsOn']) return 0;
return strtotime($b['startsOn']) - strtotime($a['startsOn']);
});
// Split the array of events into chunks of 3
$items = array_chunk($items, 4);
// Start HTML variable
$html = '';
// Show an alert if no upcoming events are scheduled, or show events
if ($totalItems <= 0) {
$html .= '<div class="events past-events">';
$html .= '<div class="alert alert-info no-events">';
$html .= 'There are no past events.';
$html .= '</div></div>';
} elseif ($totalItems > 0) {
// All upcoming events wrapper
$html .= '<div class="events past-events">';
// Cycle through each row
foreach ($items as $row) {
// Start new row
$html .= '<div class="event-row row g-3 pb-0 pb-md-3">';
foreach ($row as $event) {
// Convert start time format
$eventStartTimeObject = new DateTimeImmutable($event['startsOn'], new DateTimeZone('UTC'));
$eventStartTimeEST = $eventStartTimeObject->setTimezone(new DateTimeZone('America/New_York'));
$eventStartTimeString = $eventStartTimeEST->format('F j, Y');
// event wrapper HTML
$html .= '<div class="event-wrapper col-12 col-md-3">';
$html .= '<div class="card border-dark event-card">';
// event image if there is one
if (strlen($event['imageUrl']) > 0) {
$html .= '<a href="https://neu.campuslabs.com/engage/event/' . $event['id'] . '" class="event-img-link" target="_blank">';
$html .= '<div role="img" aria-label="Image Uploaded for Event Cover Photo" alt ="Image Uploaded for Event Cover Photo" class="card-img-top event-img border-bottom border-dark" style="background-image: url(\'' . $event['imageUrl'] . '?preset=large-w\');">';
$html .= '</div></a>';
}
// event body
$html .= '<div class="card-body event-body">';
// event title
$html .= '<a href="https://neu.campuslabs.com/engage/event/' . $event['id'] . '" class="event-title-link" target="_blank">';
$html .= '<h3 class="card-title event-title fs-5">' . $event['name'];
$html .= '</h3></a>';
// event text
$html .= '<div class="card-text event-text">';
// event date
$html .= '<div class="event-date pb-1">';
$html .= '<span class="bi bi-pe-1 bi-calendar2-heart">' . $eventStartTimeString;
$html .= '</span></div>';
// event location
$html .= '<div class="event-location pb-3">';
$html .= '<span class="bi bi-pe-1 bi-geo-alt-fill">' . $event['address']['name'];
$html .= '</span></div>';
// event button
$html .= '<div class="event-button">';
$html .= '<a href="https://neu.campuslabs.com/engage/event/' . $event['id'] . '" class="btn btn-primary bi bi-pe-2 bi-box-arrow-up-right" target="_blank">';
$html .= 'Learn More';
$html .= '</a></div>';
// closing tags for event text, body, card, and wrapper
$html .= '</div></div></div></div>';
}
// Row closing tag
$html .= '</div>';
}
// All events closing tag
$html .= '</div>';
}
// return the html
return $html;
}
add_shortcode('past_events', 'past_events_function');