google_fonts_api.module in @font-your-face 7
File
modules/google_fonts_api/google_fonts_api.module
View source
<?php
function google_fonts_api_fontyourface_info() {
$info = array(
'name' => 'Google',
'url' => 'http://code.google.com/webfonts',
);
return $info;
}
function google_fonts_api_fontyourface_preview($font) {
return '<span style="' . fontyourface_font_css($font) . ' font-size: 24px;">' . $font->name . '</span>';
}
function google_fonts_api_fontyourface_view($font, $text) {
$output = '';
$sizes = array(
32,
24,
18,
14,
12,
10,
);
foreach ($sizes as $size) {
$output .= '<div style="' . fontyourface_font_css($font) . ' font-size: ' . $size . 'px; line-height: ' . $size . 'px;">' . $text . '</div>';
}
return $output;
}
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 (count($path_parts) > 1) {
$paths[$path_parts[0]][] = $path_parts[1];
}
else {
$paths[$path_parts[0]][] = 'regular';
}
}
}
if (count($paths) > 0) {
$families = array();
foreach ($paths as $family => $variants) {
$families[] = $family . ':' . implode(',', $variants);
}
$base = 'http://fonts.googleapis.com/css?family=';
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
$base = 'https://fonts.googleapis.com/css?family=';
}
$url = $base . implode('|', $families) . '&subset=' . implode(',', $subsets);
fontyourface_add_css_in_preprocess($vars, $url, 'remote');
}
}
}
function google_fonts_api_fontyourface_import() {
include DRUPAL_ROOT . '/' . drupal_get_path('module', 'google_fonts_api') . '/font_list.inc';
foreach ($fonts as $font) {
if (!isset($font->tags)) {
$font->tags = array();
}
fontyourface_save_font($font);
}
}