This repository has been archived by the owner on Sep 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 873
/
foundation.php
183 lines (154 loc) · 5.55 KB
/
foundation.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
<?php
/**
* Foundation PHP template
*
* @package FoundationPress
* @since FoundationPress 1.0.0
*/
// Pagination.
if ( ! function_exists( 'foundationpress_pagination' ) ) :
function foundationpress_pagination() {
global $wp_query;
$big = 999999999; // This needs to be an unlikely integer
// For more options and info view the docs for paginate_links()
// http://codex.wordpress.org/Function_Reference/paginate_links
$paginate_links = paginate_links( array(
'base' => str_replace( $big, '%#%', html_entity_decode( get_pagenum_link( $big ) ) ),
'current' => max( 1, get_query_var( 'paged' ) ),
'total' => $wp_query->max_num_pages,
'mid_size' => 5,
'prev_next' => true,
'prev_text' => __( '«', 'foundationpress' ),
'next_text' => __( '»', 'foundationpress' ),
'type' => 'list',
) );
$paginate_links = str_replace( "<ul class='page-numbers'>", "<ul class='pagination text-center'>", $paginate_links );
$paginate_links = str_replace( '<li><span class="page-numbers dots">', "<li><a href='#'>", $paginate_links );
$paginate_links = str_replace( "<li><span class='page-numbers current'>", "<li class='current'><a href='#'>", $paginate_links );
$paginate_links = str_replace( '</span>', '</a>', $paginate_links );
$paginate_links = str_replace( "<li><a href='#'>…</a></li>", "<li><span class='dots'>…</span></li>", $paginate_links );
$paginate_links = preg_replace( '/\s*page-numbers/', '', $paginate_links );
// Display the pagination if more than one page is found.
if ( $paginate_links ) {
echo $paginate_links;
}
}
endif;
/**
* A fallback when no navigation is selected by default.
*/
if ( ! function_exists( 'foundationpress_menu_fallback' ) ) :
function foundationpress_menu_fallback() {
echo '<div class="alert-box secondary">';
/* translators: %1$s: link to menus, %2$s: link to customize. */
printf( __( 'Please assign a menu to the primary menu location under %1$s or %2$s the design.', 'foundationpress' ),
/* translators: %s: menu url */
sprintf( __( '<a href="%s">Menus</a>', 'foundationpress' ),
get_admin_url( get_current_blog_id(), 'nav-menus.php' )
),
/* translators: %s: customize url */
sprintf( __( '<a href="%s">Customize</a>', 'foundationpress' ),
get_admin_url( get_current_blog_id(), 'customize.php' )
)
);
echo '</div>';
}
endif;
// Add Foundation 'is-active' class for the current menu item.
if ( ! function_exists( 'foundationpress_active_nav_class' ) ) :
function foundationpress_active_nav_class( $classes, $item ) {
if ( $item->current == 1 || $item->current_item_ancestor == true ) {
$classes[] = 'is-active';
}
return $classes;
}
add_filter( 'nav_menu_css_class', 'foundationpress_active_nav_class', 10, 2 );
endif;
/**
* Use the is-active class of ZURB Foundation on wp_list_pages output.
* From required+ Foundation http://themes.required.ch.
*/
if ( ! function_exists( 'foundationpress_active_list_pages_class' ) ) :
function foundationpress_active_list_pages_class( $input ) {
$pattern = '/current_page_item/';
$replace = 'current_page_item is-active';
$output = preg_replace( $pattern, $replace, $input );
return $output;
}
add_filter( 'wp_list_pages', 'foundationpress_active_list_pages_class', 10, 2 );
endif;
/**
* Enable Foundation responsive embeds for WP video embeds
*/
if ( ! function_exists( 'foundationpress_responsive_video_oembed_html' ) ) :
function foundationpress_responsive_video_oembed_html( $html, $url, $attr, $post_id ) {
// Whitelist of oEmbed compatible sites that **ONLY** support video.
// Cannot determine if embed is a video or not from sites that
// support multiple embed types such as Facebook.
// Official list can be found here https://codex.wordpress.org/Embeds
$video_sites = array(
'youtube', // first for performance
'collegehumor',
'dailymotion',
'funnyordie',
'ted',
'videopress',
'vimeo',
);
$is_video = false;
// Determine if embed is a video
foreach ( $video_sites as $site ) {
// Match on `$html` instead of `$url` because of
// shortened URLs like `youtu.be` will be missed
if ( strpos( $html, $site ) ) {
$is_video = true;
break;
}
}
// Process video embed
if ( true == $is_video ) {
// Find the `<iframe>`
$doc = new DOMDocument();
$doc->loadHTML( $html );
$tags = $doc->getElementsByTagName( 'iframe' );
// Get width and height attributes
foreach ( $tags as $tag ) {
$width = $tag->getAttribute('width');
$height = $tag->getAttribute('height');
break; // should only be one
}
$class = 'responsive-embed'; // Foundation class
// Determine if aspect ratio is 16:9 or wider
if ( is_numeric( $width ) && is_numeric( $height ) && ( $width / $height >= 1.7 ) ) {
$class .= ' widescreen'; // space needed
}
// Wrap oEmbed markup in Foundation responsive embed
return '<div class="' . $class . '">' . $html . '</div>';
} else { // not a supported embed
return $html;
}
}
add_filter( 'embed_oembed_html', 'foundationpress_responsive_video_oembed_html', 10, 4 );
endif;
/**
* Get mobile menu ID
*/
if ( ! function_exists( 'foundationpress_mobile_menu_id' ) ) :
function foundationpress_mobile_menu_id() {
if ( get_theme_mod( 'wpt_mobile_menu_layout' ) === 'offcanvas' ) {
echo 'off-canvas-menu';
} else {
echo 'mobile-menu';
}
}
endif;
/**
* Get title bar responsive toggle attribute
*/
if ( ! function_exists( 'foundationpress_title_bar_responsive_toggle' ) ) :
function foundationpress_title_bar_responsive_toggle() {
if ( ! get_theme_mod( 'wpt_mobile_menu_layout' ) || get_theme_mod( 'wpt_mobile_menu_layout' ) === 'topbar' ) {
echo 'data-responsive-toggle="mobile-menu"';
}
}
endif;