forked from reduxframework/google-fonts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.php
155 lines (132 loc) · 3.68 KB
/
run.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/**
* getSubsets Function.
* Clean up the Google Webfonts subsets to be human readable
*
* @since ReduxFramework 0.2.0
*/
function getSubsets( $var ) {
$result = array();
foreach ( $var as $v ) {
if ( strpos( $v, "-ext" ) ) {
$name = ucfirst( str_replace( "-ext", " Extended", $v ) );
} else {
$name = ucfirst( $v );
}
$result[ $v ] = $name;
/*array_push( $result, array(
'id' => $v,
'name' => $name,
) );*/
}
return array_filter( $result );
} //function
/**
* getVariants Function.
* Clean up the Google Webfonts variants to be human readable
*
* @since ReduxFramework 0.2.0
*/
function getVariants( $var ) {
$result = array( 'exists' => array() );
$italic = array();
foreach ( $var as $v ) {
$name = "";
if ( $v[0] == 1 ) {
$name = 'Thin 100';
} elseif ( $v[0] == 2 ) {
$name = 'Extra Light 200';
} elseif ( $v[0] == 3 ) {
$name = 'Light 300';
} elseif ( $v[0] == 4 || $v[0] == "r" || $v[0] == "i" ) {
$name = 'Regular 400';
} elseif ( $v[0] == 5 ) {
$name = 'Medium 500';
} elseif ( $v[0] == 6 ) {
$name = 'Semi-Bold 600';
} elseif ( $v[0] == 7 ) {
$name = 'Bold 700';
} elseif ( $v[0] == 8 ) {
$name = 'Extra Bold 800';
} elseif ( $v[0] == 9 ) {
$name = 'Black 900';
}
if ( $v == "regular" ) {
$v = "400";
}
if ( strpos( $v, "italic" ) || $v == "italic" ) {
$name .= " Italic";
$name = trim( $name );
if ( $v == "italic" ) {
$v = "400italic";
}
/*$italic[] = array(
'id' => $v,
'name' => $name,
);*/
$italic[ $v ] = $name;
} else {
/*$result[] = array(
'id' => $v,
'name' => $name,
);*/
$result[ $v ] = $name;
}
}
foreach ( $italic as $key => $item ) {
if ( ! isset( $result[ $key ] ) ) {
$result[ $key ] = $item;
} else {
$result['exists'][ $key ] = $item;
}
}
return array_filter( $result );
} //function
date_default_timezone_set( 'UTC' );
$output = shell_exec( 'git log -1' );
echo shell_exec( 'git checkout -f master' );
$gFile = dirname( __FILE__ ) . '/google_fonts.json';
$gFilePHP = dirname( __FILE__ ) . '/google_fonts.php';
if ( file_exists( $gFile ) ) {
$weekback = strtotime( date( 'jS F Y', time() + ( 60 * 60 * 24 * -7 ) ) );
$last_updated = filemtime( $gFile );
if ( $last_updated >= $weekback ) {
//echo 'Exit update. A week has not yet passed.';
//return;
}
}
$fonts = array();
$php_fonts = array();
$arrContextOptions = array(
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false,
),
);
$key = getenv( 'GOOGLEKEY' );
$result = json_decode( file_get_contents( "https://www.googleapis.com/webfonts/v1/webfonts?key={$key}", false, stream_context_create( $arrContextOptions ) ) );
foreach ( $result->items as $font ) {
$fonts[ $font->family ] = array(
'variants' => getVariants( $font->variants ),
'subsets' => getSubsets( $font->subsets ),
);
$php_fonts[ $font->family ] = array(
'variants' => getVariants( $font->variants ),
);
}
$data = json_encode( $fonts );
file_put_contents( $gFile, $data );
file_put_contents( $gFilePHP, var_export( $php_fonts, true ) );
echo "Saved new JSON\n\n";
echo shell_exec( 'git config --global user.email "[email protected]"' );
echo shell_exec( 'git config --global user.name "Travis CI"' );
echo shell_exec( 'git add -A' );
$build_number = getenv( 'TRAVIS_BUILD_NUMBER' );
echo shell_exec( "git commit -m \"Travis build: $build_number [skip ci]\"" );
$gh_token = getenv( 'GH_TOKEN' );
echo shell_exec( "git remote set-url origin https://[email protected]/wpsf/google-fonts.git > /dev/null 2>&1" );
echo "\n\n";
echo shell_exec( "git push origin master -f" );
//} else {
// echo 'something went wrong';
//}