-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfunctions.php
210 lines (177 loc) · 6.44 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
<?php
include_once 'includes/utilities.php';
include_once 'includes/config.php';
include_once 'includes/meta.php';
include_once 'includes/wp-bs-navwalker.php';
include_once 'includes/header-functions.php';
include_once 'includes/person-functions.php';
include_once 'includes/degree-functions.php';
/**
* 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>, given an array of media
* background picture <source> src's from get_media_background_picture_srcs().
*
* @param array $srcs Array of image urls that correspond to <source> src vals
* @return string
**/
function get_media_background_picture( $srcs ) {
ob_start();
if ( isset( $srcs['fallback'] ) ) :
?>
<?php
// Define classes for the <picture> element
$picture_classes = 'media-background-picture ';
if ( !isset( $srcs['xs'] ) ) {
// Hide the <picture> element at -xs breakpoint when no mobile image
// is available
$picture_classes .= 'hidden-xs-down';
}
?>
<picture class="<?php echo $picture_classes; ?>">
<?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" autoplay muted playsinline <?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();
}
/**
* Display college address information
**/
function get_contact_address_markup() {
$address = get_theme_mod( 'organization_address' );
if ( !empty( $address ) ) {
ob_start();
?>
<address class="address">
<?php echo wptexturize( nl2br( $address ) ); ?>
</address>
<?php
return ob_get_clean();
}
return;
}
/**
* Add custom layouts for the UCF Post List shortcode
**/
function colleges_post_list_layouts( $layouts ) {
return array_merge( $layouts, array(
'people' => 'People Layout',
'degree_block' => 'Degree Block Layout'
) );
}
add_filter( 'ucf_post_list_get_layouts', 'colleges_post_list_layouts', 10, 1 );
function colleges_post_list_search( $content, $posts, $atts ) {
if ( ! is_array( $posts ) && $posts !== false ) { $posts = array( $posts ); }
ob_start();
if ( $atts['layout'] === 'people' ):
?>
<?php if ( $posts ): ?>
<div class="row mb-4">
<div class="col-md-10 offset-md-1">
<div class="ucf-post-search-form" id="post-list-search-<?php echo $atts['list_id']; ?>" data-id="post-list-<?php echo $atts['list_id']; ?>">
<label class="sr-only"><?php echo $atts['search_placeholder']; ?></label>
<input class="typeahead" type="text" placeholder="<?php echo $atts['search_placeholder']; ?>">
</div>
</div>
</div>
<?php endif; ?>
<?php
else:
echo $content;
endif;
return ob_get_clean();
}
add_filter( 'ucf_post_list_search', 'colleges_post_list_search', 10, 3 );