1
|
|
|
<?php |
2
|
|
|
if ( ! defined( 'ABSPATH' ) ) return; // Exit if accessed directly |
3
|
|
|
/** |
4
|
|
|
* Google Font_Collection Class |
5
|
|
|
**/ |
6
|
|
|
// this file controls all of the data for the custom fonts used in the theme customizer |
7
|
|
|
|
8
|
|
|
// the Google_Font_Collection object is a wrapper that holds all of the individual custom fonts |
9
|
|
|
class LSX_Google_Font_Collection |
10
|
|
|
{ |
11
|
|
|
private $fonts; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Constructor |
15
|
|
|
**/ |
16
|
|
|
public function __construct($fonts) |
17
|
|
|
{ |
18
|
|
|
if(empty($fonts)) |
19
|
|
|
{ |
20
|
|
|
//we didn't get the required data |
21
|
|
|
return false; |
|
|
|
|
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
// create fonts |
25
|
|
|
foreach ($fonts as $key => $value) |
26
|
|
|
{ |
27
|
|
|
if( empty( $value["system"] ) ){ |
28
|
|
|
$this->fonts[$value["title"]] = new LSX_Google_Font($value["title"], $value["location"], $value["cssDeclaration"], $value["cssClass"]); |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* get_font_family_name_array Function |
35
|
|
|
* this function returns an array containing all of the font family names |
36
|
|
|
**/ |
37
|
|
|
function get_font_family_name_array() |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$result; |
|
|
|
|
40
|
|
|
foreach ($this->fonts as $key => $value) |
41
|
|
|
{ |
42
|
|
|
$result[] = $value->__get("title"); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
return $result; |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* get_title |
49
|
|
|
* this function returns the font title |
50
|
|
|
**/ |
51
|
|
|
function get_title($key) |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
return $this->fonts[$key]->__get("title"); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* get_location |
58
|
|
|
* this function returns the font location |
59
|
|
|
**/ |
60
|
|
|
function get_location($key) |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
return $this->fonts[$key]->__get("location"); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* get_css_declaration |
67
|
|
|
* this function returns the font css declaration |
68
|
|
|
**/ |
69
|
|
|
function get_css_declaration($key) |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
return $this->fonts[$key]->__get("cssDeclaration"); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* get_css_class_array |
77
|
|
|
* this function returns an array of css classes |
78
|
|
|
* this function is used when displaying the fancy list of fonts in the theme customizer |
79
|
|
|
* this function is used to send a JS file an array for the postMessage transport option in the theme customizer |
80
|
|
|
**/ |
81
|
|
|
function get_css_class_array() |
|
|
|
|
82
|
|
|
{ |
83
|
|
|
$result; |
|
|
|
|
84
|
|
|
foreach ($this->fonts as $key => $value) |
85
|
|
|
{ |
86
|
|
|
$result[$value->__get("title")] = $value->__get("cssClass"); |
|
|
|
|
87
|
|
|
} |
88
|
|
|
return $result; |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* get_total_number_of_fonts |
93
|
|
|
* this function returns the total number of fonts |
94
|
|
|
**/ |
95
|
|
|
function get_total_number_of_fonts() |
|
|
|
|
96
|
|
|
{ |
97
|
|
|
return count($this->fonts); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* print_theme_customizer_css_locations |
102
|
|
|
* this function prints the links to the css files for the theme customizer |
103
|
|
|
**/ |
104
|
|
|
function print_theme_customizer_css_locations() |
|
|
|
|
105
|
|
|
{ |
106
|
|
|
foreach ($this->fonts as $key => $value) |
107
|
|
|
{ |
108
|
|
|
$protocol = 'http'; |
109
|
|
|
if(is_ssl()){ $protocol.='s'; } |
110
|
|
|
?> |
111
|
|
|
<?php echo wp_keses_post( '<' ); ?>link href="<?php echo esc_attr( $protocol ); ?>://fonts.googleapis.com/css?family=<?php echo esc_attr( $value->__get( "location" ) ); ?>" rel='stylesheet' type='text/css'<?php echo wp_keses_post( '>' ); ?> |
112
|
|
|
<?php |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* print_theme_customizer_css_classes |
118
|
|
|
* this function prints the theme customizer css classes necessary to display all of the fonts |
119
|
|
|
**/ |
120
|
|
|
function print_theme_customizer_css_classes() |
|
|
|
|
121
|
|
|
{ |
122
|
|
|
?> |
123
|
|
|
<style type="text/css"> |
124
|
|
|
<?php |
125
|
|
|
foreach ($this->fonts as $key => $value) |
126
|
|
|
{ |
127
|
|
|
?> |
128
|
|
|
.<?php echo esc_attr( $value->__get( "cssClass" ) ); ?>{ |
129
|
|
|
font-family: <?php echo esc_attr( $value->__get( "cssDeclaration" ) ); ?>; |
130
|
|
|
} |
131
|
|
|
<?php |
132
|
|
|
} |
133
|
|
|
?> |
134
|
|
|
</style> |
135
|
|
|
<?php |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
} // Font_Collection |