Commit 751d52af authored by Erase's avatar Erase

Oups 3/2 o/

parent f10dea25
# goofi
get google fonts onto your server with just one <link>
instead of
```
<link href="https://fonts.googleapis.com/css?family=Nunito+Sans|Roboto" rel="stylesheet">
```
use
```
<link href="goofi.php?family=Nunito+Sans|Roboto" rel="stylesheet">
```
and the script will get the fonts & css and then save it onto your server. After that, no more queries will be send to google's servers anymore ;-)
<?php
header("Content-Type: text/css");
$font_folder='fonts';
if (!empty($_GET['family'])){
if (!is_dir($font_folder)){mkdir($font_folder);}
$family=strip_tags($_GET['family']);
$css_filename=urlencode($family).'.css';
$css_file_url='http://fonts.googleapis.com/css?family='.urlencode($family);
if (!is_file($css_filename)){
$css=file_get_contents($css_file_url);
preg_match_all("#font-family: '(?P<name>[^']+)[^^]*?url\((?P<url>[^\)]+)\)#", $css, $urls);
foreach($urls['url'] as $nb=>$url){
$font_file=$urls['name'][$nb].basename($url);
if (!is_file($font_folder.'/'.$font_file)){
$font=file_get_contents($url);
file_put_contents($font_folder.'/'.$font_file, $font);
}
$css=str_replace($url,$font_folder.'/'.$font_file,$css);
}
file_put_contents($css_filename,$css );
}else{
$css=file_get_contents($css_filename);
}
exit($css);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment