1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Build CSS for Google fonts
|
6
|
*
|
7
|
* This file exists for backwards compatibility for pre 7.x-3.x themes, it is
|
8
|
* never used in 7.x-3.x themes or newer.
|
9
|
*/
|
10
|
|
11
|
global $theme_key, $theme_name;
|
12
|
$theme_name = $theme_key;
|
13
|
$path_to_at_core = drupal_get_path('theme', 'adaptivetheme');
|
14
|
|
15
|
// Include the font definition arrays
|
16
|
include_once($path_to_at_core . '/inc/fonts.inc');
|
17
|
|
18
|
// Backwards compatibility cruft for pre 7.x-3.x subthemes that have google fonts
|
19
|
// We dont want them to use this but if saves the site blowing up if a user tries...
|
20
|
// Return a list of options
|
21
|
function google_web_fonts_list_options() {
|
22
|
$google_web_font_families = array();
|
23
|
$fonts = google_font_names();
|
24
|
foreach ($fonts as $font) {
|
25
|
$google_web_font_families[] = $font;
|
26
|
}
|
27
|
return $google_web_font_families;
|
28
|
}
|
29
|
|
30
|
// Return the style name
|
31
|
function google_web_fonts_get_style_name($key, $font_type, $font_value) {
|
32
|
$font_value = trim($font_value);
|
33
|
$font_value = strtolower($font_value);
|
34
|
$font_value = str_replace(' ', '-', $font_value);
|
35
|
return $key . (!empty($font_type) ? '-' . $font_type : "") . "-" . $font_value;
|
36
|
}
|
37
|
|
38
|
// Process font families, this is not specific to Google fonts but makes sense including it here
|
39
|
function get_font_families($fonts, $theme_name) {
|
40
|
$google_font_families = array();
|
41
|
$font_type = '';
|
42
|
$font_families = array();
|
43
|
foreach ($fonts as $key => $value) {
|
44
|
$font_type = theme_get_setting($value . '_type', $theme_name);
|
45
|
$font_value = theme_get_setting($value . (!empty($font_type) ? '_' . $font_type : ''), $theme_name);
|
46
|
if ($font_type == '') {
|
47
|
$font_families[] = $font_value;
|
48
|
}
|
49
|
else {
|
50
|
if ($font_type == 'gwf') {
|
51
|
$gff = str_replace(' ', '+', $font_value);
|
52
|
$google_font_families[] = $gff;
|
53
|
$font_value = preg_replace('/[^\w\d_ -]/si', '', $font_value);
|
54
|
$style_name = google_web_fonts_get_style_name($key, $font_type, $font_value);
|
55
|
$font_families[] = $style_name;
|
56
|
switch ($key) {
|
57
|
case 'bf':
|
58
|
drupal_add_css("body.$style_name, .$style_name .form-text {font-family: '" . $font_value . "'}", array('group' => CSS_DEFAULT, 'type' => 'inline'));
|
59
|
break;
|
60
|
case 'snf':
|
61
|
drupal_add_css("body.$style_name #site-name {font-family : '" . $font_value . "'}", array('group' => CSS_DEFAULT, 'type' => 'inline'));
|
62
|
break;
|
63
|
case 'ssf':
|
64
|
drupal_add_css("body.$style_name #site-slogan {font-family: '" . $font_value . "'}", array('group' => CSS_DEFAULT, 'type' => 'inline'));
|
65
|
break;
|
66
|
case 'mmf':
|
67
|
drupal_add_css(".$style_name #nav-wrapper {font-family: '" . $font_value . "'}", array('group' => CSS_DEFAULT, 'type' => 'inline'));
|
68
|
break;
|
69
|
case 'ptf':
|
70
|
drupal_add_css("body.$style_name #page-title {font-family: '" . $font_value . "'}", array('group' => CSS_DEFAULT, 'type' => 'inline'));
|
71
|
break;
|
72
|
case 'ntf':
|
73
|
drupal_add_css("body.$style_name .article-title {font-family: '" . $font_value . "'}", array('group' => CSS_DEFAULT, 'type' => 'inline'));
|
74
|
break;
|
75
|
case 'ctf':
|
76
|
drupal_add_css("body.$style_name .comment-title {font-family: '" . $font_value . "'}", array('group' => CSS_DEFAULT, 'type' => 'inline'));
|
77
|
break;
|
78
|
case 'btf':
|
79
|
drupal_add_css("body.$style_name .block-title {font-family: '" . $font_value . "'}", array('group' => CSS_DEFAULT, 'type' => 'inline'));
|
80
|
break;
|
81
|
}
|
82
|
}
|
83
|
}
|
84
|
}
|
85
|
if (!empty($google_font_families)) {
|
86
|
$array = array_unique($google_font_families);
|
87
|
$google_fonts = trim(implode('|', $array));
|
88
|
drupal_add_css('//fonts.googleapis.com/css?family=' . $google_fonts, array(
|
89
|
'group' => CSS_THEME,
|
90
|
'type' => 'external',
|
91
|
'weight' => -1,
|
92
|
'preprocess' => FALSE,
|
93
|
)
|
94
|
);
|
95
|
}
|
96
|
return $font_families;
|
97
|
}
|