-
Notifications
You must be signed in to change notification settings - Fork 1
/
font-functions.php
131 lines (98 loc) · 2.47 KB
/
font-functions.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
<?php
function PageCDN_rewriter_rewrite_google_fonts( $match )
{
Global $PageCDN_fonts ,
$PageCDN_max_font_URLs ;
if( count( $PageCDN_fonts ) > $PageCDN_max_font_URLs )
{
return '';
}
if( strlen( $match[0] ) && strlen( $match[1] ) )
{
$url = trim( $match[1] , '\'"' );
$url = parse_url( $url );
if( isset( $url['query'] ) )
{
parse_str( $url['query'] , $vars );
foreach( $vars as $key => $val )
{
if( $key == 'family' )
{
$family = $val;
}
}
}
foreach( explode( '|' , $family ) as $ifamily )
{
if( strpos( $ifamily , ':' ) )
{
$ifamily = substr( $ifamily , 0 , strpos( $ifamily , ':' ) );
}
$family_name = str_replace( ' ' , '-' , strtolower( $ifamily ) ) . '.css';
$PageCDN_fonts[$family_name] = true;
if( count( $PageCDN_fonts ) > $PageCDN_max_font_URLs )
{
return '';
}
}
return '';
}
}
function PageCDN_rewriter_rewrite_easy_fonts( $match )
{
Global $PageCDN_fonts ,
$PageCDN_max_font_URLs ;
if( count( $PageCDN_fonts ) > $PageCDN_max_font_URLs )
{
return '';
}
if( strlen( $match[0] ) && strlen( $match[1] ) )
{
$url = trim( $match[1] , '\'"' );
$url = str_replace( 'http://pagecdn.io/lib/easyfonts/' , '' , $url );
$family = str_replace( 'https://pagecdn.io/lib/easyfonts/' , '' , $url );
if( strpos( $family , '?' ) !== false )
{
$family = substr( $family , 0 , strpos( $family , '?' ) );
}
if( $family == 'fonts.css' ) # Importing all fonts
{
$PageCDN_fonts = array_fill( 0 , $PageCDN_max_font_URLs + 1 , '' );
return '';
}
$PageCDN_fonts[$family] = true;
return '';
}
}
function PageCDN_rewriter_insert_fonts( $html )
{
Global $PageCDN_fonts ,
$PageCDN_max_font_URLs ;
$code = '';
$base = 'https://pagecdn.io/lib/easyfonts/';
if( count( $PageCDN_fonts ) > $PageCDN_max_font_URLs )
{
$code .= "\n<link rel=\"stylesheet\" href=\"{$base}fonts.css\" />";
}
else
{
foreach( $PageCDN_fonts as $family => $scrap )
{
$code .= "\n<link rel=\"stylesheet\" href=\"{$base}{$family}\" />";
}
}
$pos = strpos( $html , '</head>' );
if( $pos === false )
{
$pos = strpos( strtolower( $html ) , '</head>' );
}
if( $pos === false )
{
$html = $code . $html;
}
else
{
$html = substr_replace( $html, $code.'</head>' , $pos, 7 );
}
return $html;
}