-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfunctions.php
598 lines (511 loc) · 19.5 KB
/
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
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
<?php
include_once 'includes/utilities.php';
include_once 'includes/config.php';
include_once 'includes/meta.php';
include_once 'includes/navwalker.php';
include_once 'includes/header-functions.php';
include_once 'includes/location-functions.php';
include_once 'includes/degree-functions.php';
include_once 'includes/ucf-alert-functions.php';
include_once 'includes/phonebook-functions.php';
include_once 'includes/post-list-layouts.php';
/**
* Displays a list of top degrees for the colleges taxonomy template
* @author RJ Bruneel
* @since 3.0.0
* @param $term object | Object with top degrees
* @return string | Top Degrees List.
**/
function display_top_degrees( $term ) {
$ret = "";
$top_degrees = get_field( 'top_degrees', $term );
if ( $top_degrees ) :
foreach ( $top_degrees as $top_degree ) :
// Ensure stale degrees are omitted from this list:
if ( $top_degree->post_status === 'publish' ):
$ret .= '<li><a href="' . get_permalink( $top_degree->ID ) . '" class="text-inverse nav-link">' . $top_degree->post_title . '</a></li>';
endif;
endforeach;
endif;
$top_degrees_custom = get_field( 'top_degrees_custom', $term );
if ( $top_degrees_custom ) :
foreach ( $top_degrees_custom as $top_degree_custom ) :
$ret .= '<li><a href="' . $top_degree_custom["top_degree_custom_link"] . '" class="text-inverse nav-link">' . $top_degree_custom["top_degree_custom_text"] . '</a></li>';
endforeach;
endif;
return $ret;
}
/**
* Returns an array of src's for a media background <picture>'s <source>s by
* breakpoint.
*
* $img_size_prefix is expected to be a prefix for a set of registered image
* sizes, which has dimensions defined for each of Athena's responsive
* breakpoints. For example, if given a prefix 'bg-img', it is expected that
* bg-img, bg-img-sm, bg-img-md, bg-img-lg, and bg-img-xl are valid registered
* image sizes.
*
* @param int $attachment_xs_id Attachment ID for the image to be used at the -xs breakpoint
* @param int $attachment_sm_id Attachment ID for the image to be used at the -sm breakpoint and up
* @param string $img_size_prefix Prefix for a set of image sizes
* @return array
**/
function get_media_background_picture_srcs( $attachment_xs_id, $attachment_sm_id, $img_size_prefix ) {
$bg_images = array();
if ( $attachment_sm_id ) {
$bg_images = array_merge(
$bg_images,
array(
'xl' => get_attachment_src_by_size( $attachment_sm_id, $img_size_prefix . '-xl' ),
'lg' => get_attachment_src_by_size( $attachment_sm_id, $img_size_prefix . '-lg' ),
'md' => get_attachment_src_by_size( $attachment_sm_id, $img_size_prefix . '-md' ),
'sm' => get_attachment_src_by_size( $attachment_sm_id, $img_size_prefix . '-sm' )
)
);
// Try to get a fallback -xs image if needed
if ( !$attachment_xs_id ) {
$bg_images = array_merge(
$bg_images,
array( 'xs' => get_attachment_src_by_size( $attachment_sm_id, $img_size_prefix ) )
);
}
// Remove duplicate image sizes, in case an old image isn't pre-cropped
$bg_images = array_unique( $bg_images );
// Use the largest-available image as the fallback <img>
$bg_images['fallback'] = reset( $bg_images );
}
if ( $attachment_xs_id ) {
$bg_images = array_merge(
$bg_images,
array( 'xs' => get_attachment_src_by_size( $attachment_xs_id, $img_size_prefix ) )
);
}
// Strip out false-y values (in case an attachment failed to return somewhere)
$bg_images = array_filter( $bg_images );
return $bg_images;
}
/**
* Returns markup for a media background <picture>.
*
* @param array $srcs Array of image urls that correspond to <source> src vals. Expects output from get_media_background_picture_srcs()
* @return string
**/
function get_media_background_picture( $srcs ) {
ob_start();
if ( isset( $srcs['fallback'] ) ) :
?>
<picture class="media-background-picture">
<?php if ( isset( $srcs['xl'] ) ) : ?>
<source srcset="<?php echo $srcs['xl']; ?>" media="(min-width: 1200px)">
<?php endif; ?>
<?php if ( isset( $srcs['lg'] ) ) : ?>
<source srcset="<?php echo $srcs['lg']; ?>" media="(min-width: 992px)">
<?php endif; ?>
<?php if ( isset( $srcs['md'] ) ) : ?>
<source srcset="<?php echo $srcs['md']; ?>" media="(min-width: 768px)">
<?php endif; ?>
<?php if ( isset( $srcs['sm'] ) ) : ?>
<source srcset="<?php echo $srcs['sm']; ?>" media="(min-width: 576px)">
<?php endif; ?>
<?php if ( isset( $srcs['xs'] ) ) : ?>
<source srcset="<?php echo $srcs['xs']; ?>" media="(max-width: 575px)">
<?php endif; ?>
<img class="media-background object-fit-cover" src="<?php echo $srcs['fallback']; ?>" alt="">
</picture>
<?php
endif;
return ob_get_clean();
}
/**
* Returns markup for a media background <video> element.
*
* $videos is expected to be an array whose keys correspond to supported
* <source> filetypes; e.g. $videos = array( 'webm' => '...', 'mp4' => '...' ).
* Values should be video urls.
*
* Note: we never display autoplay videos at the -xs breakpoint.
*
* @param array $videos Array of video urls that correspond to <source> src vals
* @return string
**/
function get_media_background_video( $videos, $loop=false ) {
ob_start();
?>
<video class="hidden-xs-down media-background media-background-video object-fit-cover" aria-hidden="true" preload="none" muted <?php if ( $loop ) { ?>loop<?php } ?>>
<?php if ( isset( $videos['webm'] ) ) : ?>
<source src="<?php echo $videos['webm']; ?>" type="video/webm">
<?php endif; ?>
<?php if ( isset( $videos['mp4'] ) ) : ?>
<source src="<?php echo $videos['mp4']; ?>" type="video/mp4">
<?php endif; ?>
</video>
<button class="media-background-video-toggle btn play-enabled hidden-xs-up" type="button" data-toggle="button" aria-pressed="false" aria-label="Play or pause background videos">
<span class="fa fa-pause media-background-video-pause" aria-hidden="true"></span>
<span class="fa fa-play media-background-video-play" aria-hidden="true"></span>
</button>
<?php
return ob_get_clean();
}
/**
* Section markup override
**/
function add_section_markup_before( $content, $section, $class, $title, $section_id ) {
// Retrieve background image sizes
$bg_image_sm_id = get_field( 'section_background_image', $section->ID ); // -sm+
$bg_image_xs_id = get_field( 'section_background_image_xs', $section->ID ); // -xs only
$bg_images = get_media_background_picture_srcs( $bg_image_xs_id, $bg_image_sm_id, 'bg-img' );
// Retrieve color classes/custom definitions
$bg_color = get_field( 'section_background_color', $section->ID );
$bg_color_custom = get_field( 'section_background_color_custom', $section->ID );
$text_color = get_field( 'section_text_color', $section->ID );
$text_color_custom = get_field( 'section_text_color_custom', $section->ID );
// Define classes for the section
$section_classes = '';
if ( $class ) {
$section_classes = $class;
}
if ( isset( $bg_images['fallback'] ) ) {
$section_classes .= ' media-background-container';
}
if ( $bg_color && !empty( $bg_color ) && $bg_color !== 'custom' ) {
$section_classes .= ' ' . $bg_color;
}
if ( $text_color && !empty( $text_color ) && $text_color !== 'custom' ) {
$section_classes .= ' ' . $text_color;
}
// Define custom style attribute values for the section
$style_attrs = '';
if ( $bg_color === 'custom' && $bg_color_custom ) {
$style_attrs .= 'background-color: '. $bg_color_custom .'; ';
}
if ( $text_color === 'custom' && $text_color_custom ) {
$style_attrs .= 'color: '. $text_color_custom .'; ';
}
$title = ! empty( $title ) ? ' data-section-link-title="' . $title . '" aria-label="' . $title . '"' : '';
$section_id = ! empty( $section_id ) ? 'id="' . $section_id . '" ' : '';
ob_start();
?>
<section <?php echo $section_id; ?>class="<?php echo $section_classes; ?>" style="<?php echo $style_attrs; ?>"<?php echo $title; ?>>
<?php echo get_media_background_picture( $bg_images ); ?>
<?php
return ob_get_clean();
}
add_filter( 'ucf_section_display_before', 'add_section_markup_before', 10, 5 );
function add_section_markup( $output, $section ) {
$container = get_field( 'section_add_content_container', $section->ID );
ob_start();
?>
<?php if ( $container ) : ?>
<div class="container"><?php echo apply_filters( 'the_content', $section->post_content ); ?></div>
<?php else : ?>
<?php echo apply_filters( 'the_content', $section->post_content ); ?>
<?php endif; ?>
<?php
return ob_get_clean();
}
add_filter( 'ucf_section_display', 'add_section_markup', 10, 2 );
/**
* Events - classic layout overrides
**/
function mainsite_events_display_classic( $content, $items, $args, $display_type ) {
if ( $items && ! is_array( $items ) ) { $items = array( $items ); }
ob_start();
?>
<div class="ucf-events-list">
<?php if ( $items ): ?>
<?php
foreach( $items as $event ) :
$starts = new DateTime( $event->starts );
$ends = new DateTime( $event->ends );
?>
<div class="ucf-event ucf-event-row">
<div class="ucf-event-col ucf-event-when">
<time class="ucf-event-start-datetime" datetime="<?php echo $starts->format( 'c' ); ?>">
<span class="ucf-event-start-month"><?php echo $starts->format( 'M' ); ?></span>
<span class="ucf-event-start-date"><?php echo $starts->format( 'j' ); ?></span>
</time>
</div>
<div class="ucf-event-col ucf-event-content">
<a class="ucf-event-link" href="<?php echo $event->url; ?>">
<span class="ucf-event-title"><?php echo $event->title; ?></span>
<span class="ucf-event-time">
<span class="ucf-event-start-time"><?php echo $starts->format( 'g:i a' ); ?></span>
-
<span class="ucf-event-end-time"><?php echo $ends->format( 'g:i a' ); ?></span>
</span>
</a>
</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<span class="ucf-events-error">No events found.</span>
<?php endif; ?>
</div>
<?php
return ob_get_clean();
}
add_filter( 'ucf_events_display_classic', 'mainsite_events_display_classic', 11, 4 );
/**
* Academic Calendar Main-Site Layout
**/
function main_site_academic_calendar_before( $content, $items, $args ) {
return '<div class="academic-calendar-container">';
}
add_filter( 'ucf_acad_cal_display_main_site_before', 'main_site_academic_calendar_before', 10, 3 );
function main_site_academic_calendar_title( $content, $items, $args ) {
$title = isset( $args['title'] ) ? $args['title'] : 'Academic Calendar';
ob_start();
?>
<h2 class="mt-2 mb-4 mb-md-5 text-inverse"><span class="fa fa-calendar text-primary align-top" aria-hidden="true"></span> <?php echo $title; ?></h2>
<?php
return ob_get_clean();
}
add_filter( 'ucf_acad_cal_display_main_site_title', 'main_site_academic_calendar_title', 10, 3 );
function main_site_academic_calendar_content( $content, $items, $args, $fallback_message ) {
ob_start();
?>
<div class="row pt-2 pt-md-0">
<div class="col-lg-4 mb-4 mb-lg-0">
<h3 class="h5 mb-3"><span class="badge badge-inverse">Up Next</span></h3>
<?php
if ( !empty( $items ) ) :
$first_item = array_shift( $items );
?>
<div class="academic-calendar-item">
<a href="<?php echo $first_item->directUrl; ?>" target="_blank">
<span class="text-inverse title h4 mb-3 d-block"><?php echo $first_item->summary; ?></span>
<?php echo main_site_academic_calendar_format_date( $first_item->dtstart, $first_item->dtend ); ?>
<?php if ( ! empty( $first_item->description ) ) : ?>
<p class="text-inverse"><?php echo $first_item->description; ?></p>
<?php endif; ?>
</a>
</div>
<?php else: ?>
<div class="ucf-academic-calendar-error"><?php echo $fallback_message; ?></div>
<?php endif; ?>
</div>
<div class="col-lg-7 offset-lg-1">
<h3 class="h5 mb-3"><span class="badge badge-inverse">Looking Ahead</span></h3>
<?php if ( !empty( $items ) ) : ?>
<div class="academic-calendar-columns">
<?php foreach ( $items as $item ) : ?>
<div class="academic-calendar-item">
<a href="<?php echo $item->directUrl; ?>" target="_blank">
<?php echo main_site_academic_calendar_format_date( $item->dtstart, $item->dtend ); ?>
<span class="text-inverse title"><?php echo $item->summary; ?></span>
</a>
</div>
<?php endforeach; ?>
</div>
<?php else: ?>
<div class="ucf-academic-calendar-error"><?php echo $fallback_message; ?></div>
<?php endif; ?>
</div>
</div>
<?php
return ob_get_clean();
}
function main_site_academic_calendar_format_date( $start_date, $end_date ) {
$start_date = strtotime( $start_date );
$end_date = strtotime( $end_date );
ob_start();
?>
<div class="time text-primary">
<time datetime="<?php echo date( 'Y-m-d', $start_date ); ?>"><?php echo date( 'F j', $start_date ); ?></time>
<?php
if ( $end_date ) :
if ( date( 'F', $start_date ) === date( 'F', $end_date ) ) :
?>
- <time datetime="<?php echo date( 'Y-m-d', $end_date ); ?>"><?php echo date( 'j', $end_date ); ?></time>
<?php else: ?>
- <time datetime="<?php echo date( 'Y-m-d', $end_date ); ?>"><?php echo date( 'F j', $end_date ); ?></time>
<?php endif;
endif;
?>
</div>
<?php
return ob_get_clean();
}
add_filter( 'ucf_acad_cal_display_main_site', 'main_site_academic_calendar_content', 10, 4 );
function main_site_academic_calendar_after( $content, $items, $args ) {
return '</div>';
}
add_filter( 'ucf_acad_cal_display_main_site_after', 'main_site_academic_calendar_after', 10, 3 );
function main_site_academic_calendar_add_layout( $layouts ) {
if ( ! isset( $layouts['main_site'] ) ) {
$layouts['main_site'] = 'Main Site Layout';
}
return $layouts;
}
add_filter( 'ucf_acad_cal_get_layouts', 'main_site_academic_calendar_add_layout', 10, 1 );
/**
* Main-Site Pegasus List Layout
**/
function main_site_pegasus_list_before( $content, $items, $args ) {
ob_start();
?>
<div class="ucf-pegasus-list ucf-pegasus-list-main-site">
<?php
return ob_get_clean();
}
add_filter( 'ucf_pegasus_list_display_main_site_before', 'main_site_pegasus_list_before', 10, 3 );
function main_site_pegasus_list_content( $content, $items, $args, $fallback_message='' ) {
if ( $items && ! is_array( $items ) ) { $items = array( $items ); }
$first = null;
if ( $items ) {
$first = array_shift( $items );
}
ob_start();
?>
<?php
if ( $first ) :
$issue_url = $first->link;
$issue_title = $first->title->rendered;
$cover_story = $first->_embedded->issue_cover_story[0];
$cover_story_url = $cover_story->link;
$cover_story_title = $cover_story->title->rendered;
$cover_story_subtitle = $cover_story->story_subtitle;
$cover_story_description = $cover_story->story_description;
$cover_story_blurb = null;
$thumbnail_id = $first->featured_media;
$thumbnail = null;
$thumbnail_url = null;
if ( $thumbnail_id !== 0 ) {
$thumbnail = $first->_embedded->{"wp:featuredmedia"}[0];
$thumbnail_url = $thumbnail->media_details->sizes->full->source_url;
}
if ( $cover_story_description ) {
$cover_story_blurb = $cover_story_description;
} else if ( $cover_story_subtitle ) {
$cover_story_blurb = $cover_story_subtitle;
}
?>
<!-- Featured Issue -->
<div class="row mb-4 mb-md-5">
<div class="col-sm-4">
<a class="h2 mb-2" href="<?php echo $issue_url; ?>" target="_blank">
<img class="w-100" src="<?php echo $thumbnail_url; ?>" alt="<?php echo $issue_title; ?>">
</a>
</div>
<div class="col-sm-8 mt-3 mt-sm-0">
<a class="h1 text-secondary" href="<?php echo $issue_url; ?>" target="_blank">
<?php echo $issue_title; ?>
</a>
<p class="mt-2 mt-md-4 mb-2 text-muted text-uppercase">Featured Story</p>
<a class="h3 font-slab-serif text-secondary" href="<?php echo $cover_story_url; ?>" target="_blank">
<?php echo $cover_story_title; ?>
</a>
<p class="mt-3 mb-4"><?php echo $cover_story_blurb; ?></p>
<a class="btn btn-primary" href="<?php echo $issue_url; ?>" target="_blank">
Read More<span class="sr-only"> from <?php echo $issue_title; ?></span>
</a>
</div>
</div>
<?php elseif ( $fallback_message ) : ?>
<p><?php echo $fallback_message; ?></p>
<?php endif; ?>
<?php if ( $items ) : ?>
<hr class="hidden-lg-up my-4 my-md-5">
<div class="row">
<?php
foreach ( $items as $item ) :
$issue_url = $item->link;
$issue_title = $item->title->rendered;
$cover_story = $item->_embedded->issue_cover_story[0];
$cover_story_url = $cover_story->link;
$cover_story_title = $cover_story->title->rendered;
$cover_story_subtitle = $cover_story->story_subtitle;
$cover_story_description = $cover_story->story_description;
$cover_story_blurb = null;
$thumbnail_id = $item->featured_media;
$thumbnail = null;
$thumbnail_url = null;
if ( $thumbnail_id !== 0 ) {
$thumbnail = $item->_embedded->{"wp:featuredmedia"}[0];
$thumbnail_url = $thumbnail->media_details->sizes->full->source_url;
}
if ( $cover_story_description ) {
$cover_story_blurb = $cover_story_description;
} else if ( $cover_story_subtitle ) {
$cover_story_blurb = $cover_story_subtitle;
}
?>
<div class="col-lg-3 mb-4">
<div class="row">
<div class="col-3 col-lg-12 pr-0 pr-sm-3">
<a class="text-secondary" href="<?php echo $issue_url; ?>" target="_blank">
<img class="w-100 mb-3" src="<?php echo $thumbnail_url; ?>" alt="<?php echo $issue_title; ?>">
</a>
</div>
<div class="col-9 col-lg-12">
<a class="h3 text-secondary" href="<?php echo $issue_url; ?>" target="_blank">
<?php echo $issue_title; ?>
</a>
<p class="mt-2 mt-md-3 mb-1 small text-muted text-uppercase">Featured Story</p>
<a class="h5 font-slab-serif text-secondary mb-3" href="<?php echo $cover_story_url; ?>" target="_blank">
<?php echo $cover_story_title; ?>
</a>
<p class="my-2"><?php echo $cover_story_blurb; ?></p>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php
return ob_get_clean();
}
add_filter( 'ucf_pegasus_list_display_main_site_content', 'main_site_pegasus_list_content', 10, 4 );
function main_site_pegasus_list_after( $content, $items, $args ) {
ob_start();
?>
</div>
<?php
return ob_get_clean();
}
add_filter( 'ucf_pegasus_list_display_main_site_after', 'main_site_pegasus_list_after', 10, 3 );
function main_site_pegasus_add_layout( $layouts ) {
if ( ! isset( $layouts['main_site'] ) ) {
$layouts['main_site'] = 'Main Site Layout';
}
return $layouts;
}
add_filter( 'ucf_pegasus_list_get_layouts', 'main_site_pegasus_add_layout', 10, 1 );
/**
* Returns markup for the colleges grid (without intro text).
*
* @author Jo Dickson
* @since v3.0.5
* @param obj $exclude_term College term object to exclude from the grid
* @return string Colleges grid HTML
*/
function get_colleges_grid( $exclude_term=null ) {
$colleges = get_terms( array( 'taxonomy' => 'colleges', 'hide_empty' => false ) );
ob_start();
if ( $colleges ):
?>
<section class="section-colleges">
<div class="jumbotron jumbotron-fluid bg-primary py-4 my-0 text-center">
<div class="container">
<h2 class="section-heading h3 m-0 text-uppercase font-weight-bold font-condensed">University of Central Florida Colleges</h2>
</div>
</div>
<div class="colleges-grid">
<?php foreach( $colleges as $index=>$college ) :
if( !$exclude_term || ( $exclude_term && $college->slug !== $exclude_term->slug ) ) :
?>
<a class="colleges-block media-background-container text-inverse hover-text-inverse text-decoration-none justify-content-end" href="<?php echo get_term_link( $college ); ?>">
<img class="media-background object-fit-cover filter-sepia hover-filter-none" src="<?php echo get_field( 'thumbnail_image', 'colleges_' . $college->term_id ); ?>" alt="">
<span class="colleges-block-text pointer-events-none font-condensed text-uppercase"><?php echo get_field( 'colleges_alias', 'colleges_' . $college->term_id ); ?></span>
</a>
<?php
endif;
endforeach;
?>
</div>
</section>
<?php
endif;
return ob_get_clean();
}
?>