1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Extract font data from form values, send for processing and print
|
6
|
* returned data in a CSS file.
|
7
|
*/
|
8
|
function at_core_submit_fonts($values, $theme_name, $path) {
|
9
|
|
10
|
// $font_styles_data holds all data for the stylesheet
|
11
|
$font_styles_data = array();
|
12
|
|
13
|
// Get the font elements array.
|
14
|
$font_elements = font_elements();
|
15
|
|
16
|
// Check if fontyourface is enabled, doing this in the loop will be expensive
|
17
|
$font_your_face_enabled = font_your_face_fonts_enabled();
|
18
|
|
19
|
// Find the right font for each element
|
20
|
foreach ($font_elements as $key => $value) {
|
21
|
|
22
|
// Each item in $font_elements has 3 key value pairs
|
23
|
$element = $value['element'] ? $value['element'] : ''; // a key to use later
|
24
|
$selector = $value['selector'] ? $value['selector'] : ''; // the selector to use when building the CSS
|
25
|
$setting = $value['setting'] ? $value['setting'] : ''; // the theme setting used to retrieve the font values
|
26
|
|
27
|
// Deal with the custom CSS selectors.
|
28
|
if ($selector == 'custom_css' && !empty($values['selectors_css'])) {
|
29
|
$selector = filter_xss($values['selectors_css']); // sanitize user entered data
|
30
|
}
|
31
|
if ($selector == 'custom_css' && empty($values['selectors_css'])) {
|
32
|
$selector = 'ruby ruby'; // Valid but highly unlikely to ever match anything
|
33
|
}
|
34
|
|
35
|
// Get the font type if isset, not all font settings have a type
|
36
|
if (isset($values[$setting . '_type'])) {
|
37
|
$font_type = $values[$setting . '_type'];
|
38
|
}
|
39
|
else {
|
40
|
$font_type = '<none>'; // this is an individual "in-content" heading
|
41
|
}
|
42
|
|
43
|
// Get the font size if isset, not all font settings have size
|
44
|
if (isset($values[$setting . '_size'])) {
|
45
|
$font_size = $values[$setting . '_size'];
|
46
|
}
|
47
|
else {
|
48
|
$font_size = '<none>'; // this is a grouped "in-content" heading or custom selectors
|
49
|
}
|
50
|
|
51
|
// Get the font value (the font name or family) for the right font type if isset,
|
52
|
// not all font settings have a value
|
53
|
if (isset($values[$setting . (!empty($font_type) ? '_' . $font_type : '')])) {
|
54
|
$font_value = $values[$setting . (!empty($font_type) ? '_' . $font_type : '')];
|
55
|
}
|
56
|
|
57
|
// Initialize the $font_values array variables
|
58
|
$font_values['font_family'] = '';
|
59
|
$font_values['font_size'] = '';
|
60
|
$font_values['font_style'] = '';
|
61
|
$font_values['font_weight'] = '';
|
62
|
|
63
|
// Some Content Headings have no type or family, we add these first,
|
64
|
// these are the h1 to h6 settings that only have a size
|
65
|
if ($font_type === '<none>') {
|
66
|
$font_values['font_size'] = $font_size;
|
67
|
|
68
|
// Add styles to the array for printing into the stylsheet
|
69
|
$font_styles_data[] = at_build_font_families($element, $selector, $font_values);
|
70
|
}
|
71
|
|
72
|
// Websafe Fonts
|
73
|
if ($font_type === '') {
|
74
|
// Get a list of websafe fonts
|
75
|
$websafe_fonts = websafe_fonts_list($element);
|
76
|
// Loop over the websafe fonts list and get a match
|
77
|
foreach ($websafe_fonts as $k => $v) {
|
78
|
if ($k == $font_value) {
|
79
|
$font_family = $v;
|
80
|
}
|
81
|
}
|
82
|
$font_values['font_family'] = $font_family;
|
83
|
$font_values['font_size'] = $font_size;
|
84
|
|
85
|
// Add styles to the array for printing into the stylsheet
|
86
|
$font_styles_data[] = at_build_font_families($element, $selector, $font_values);
|
87
|
}
|
88
|
|
89
|
// Custom Font stacks (user entered data)
|
90
|
if ($font_type === 'cfs') {
|
91
|
$font_values['font_family'] = drupal_strip_dangerous_protocols($font_value); // sanitize user entered data
|
92
|
$font_values['font_size'] = $font_size;
|
93
|
// Add styles to the array for printing into the stylsheet
|
94
|
$font_styles_data[] = at_build_font_families($element, $selector, $font_values);
|
95
|
}
|
96
|
|
97
|
// Google Fonts (user entered data)
|
98
|
if ($font_type === 'gwf') {
|
99
|
$font_value = "'" . $font_value . "'";
|
100
|
$font_values['font_family'] = filter_xss_admin($font_value); // sanitize user entered data
|
101
|
$font_values['font_size'] = $font_size;
|
102
|
|
103
|
// Add styles to the array for printing into the stylsheet
|
104
|
$font_styles_data[] = at_build_font_families($element, $selector, $font_values);
|
105
|
}
|
106
|
|
107
|
// Font Your Face
|
108
|
if ($font_your_face_enabled === TRUE) {
|
109
|
if ($font_type === 'fyf') {
|
110
|
// pull the font list, we need to iterate over it
|
111
|
$fyf_fonts = font_your_face_fonts_list($element); // this is a keyed array
|
112
|
// loop over fyf_fonts list and get a match and retrive the font name
|
113
|
foreach ($fyf_fonts as $k => $v) {
|
114
|
if ($k == $font_value) {
|
115
|
$font_value = $v;
|
116
|
}
|
117
|
}
|
118
|
// Get the font objects from font-your-face, we need additional data out
|
119
|
// of each object
|
120
|
$enabled_fonts = fontyourface_get_fonts('enabled = 1');
|
121
|
foreach ($enabled_fonts as $font) {
|
122
|
// we need to know if the $font_value matches a $font->name
|
123
|
if ($font_value == $font->name) {
|
124
|
// Now we need a buch of variables to get the font family, style and weight
|
125
|
$font_values['font_family'] = $font->css_family ? $font->css_family : '';
|
126
|
$font_values['font_style'] = $font->css_style ? $font->css_style : '';
|
127
|
$font_values['font_weight'] = $font->css_weight ? $font->css_weight : '';
|
128
|
}
|
129
|
}
|
130
|
// Load the font size
|
131
|
$font_values['font_size'] = $font_size;
|
132
|
// Add styles to the array for printing into the stylsheet
|
133
|
$font_styles_data[] = at_build_font_families($element, $selector, $font_values);
|
134
|
}
|
135
|
}
|
136
|
}
|
137
|
|
138
|
// Output data to file
|
139
|
if (!empty($font_styles_data)) {
|
140
|
$font_styles = implode("\n", $font_styles_data);
|
141
|
$font_styles = preg_replace('/^[ \t]*[\r\n]+/m', '', $font_styles);
|
142
|
$file_name = $theme_name . '.fonts.css';
|
143
|
$filepath = "$path/$file_name";
|
144
|
file_unmanaged_save_data($font_styles, $filepath, FILE_EXISTS_REPLACE);
|
145
|
}
|
146
|
}
|