function google_fonts_api_preprocess_page in @font-your-face 6.2
Same name and namespace in other branches
- 6 modules/google_fonts_api/google_fonts_api.module \google_fonts_api_preprocess_page()
- 7 modules/google_fonts_api/google_fonts_api.module \google_fonts_api_preprocess_page()
Implements template_preprocess_page().
File
- modules/
google_fonts_api/ google_fonts_api.module, line 47
Code
function google_fonts_api_preprocess_page(&$vars) {
if (!empty($vars['fontyourface'])) {
$paths = array();
$subsets = array();
foreach ($vars['fontyourface'] as $used_font) {
if ($used_font->provider == 'google_fonts_api') {
$metadata = unserialize($used_font->metadata);
$path_parts = explode(':', $metadata['path']);
$subsets[$metadata['subset']] = $metadata['subset'];
if (!isset($paths[$path_parts[0]])) {
$paths[$path_parts[0]] = array();
}
// if
if (count($path_parts) > 1) {
$paths[$path_parts[0]][] = $path_parts[1];
}
else {
$paths[$path_parts[0]][] = 'regular';
}
// else
}
// if
}
// foreach
if (count($paths) > 0) {
$families = array();
foreach ($paths as $family => $variants) {
$families[] = $family . ':' . implode(',', $variants);
}
// foreach
$base = 'http://fonts.googleapis.com/css?family=';
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
$base = 'https://fonts.googleapis.com/css?family=';
}
// if
$url = $base . implode('|', $families) . '&subset=' . implode(',', $subsets);
fontyourface_add_css_in_preprocess($vars, $url, 'remote');
if (module_exists('google_webfont_loader_api')) {
foreach ($families as $family) {
$font_info = array(
'name' => 'Google ' . $family,
'google_families' => array(
$family,
),
);
_google_webfont_loader_api_load_font($font_info);
}
// foreach
}
// if
}
// if
}
// if
}