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