4 * Implements hook_fontyourface_info().
6 function fontsquirrel_fontyourface_info() {
9 'name' => 'Font Squirrel',
10 'url' => 'http://www.fontsquirrel.com/',
13 } // fontsquirrel_fonts_api_fontyourface_info
16 * Implements hook_fontyourface_preview().
18 function fontsquirrel_fontyourface_preview($font) {
20 $metadata = unserialize($font->metadata
);
22 return '<img src="http://www.fontsquirrel.com/utils/makeFont.php?font=' .
$metadata['id'] .
'/' .
$metadata['font_filename'] .
'&width=300&size=18&text=' .
urlencode($font->name
) .
'" />';
24 } // fontsquirrel_fontyourface_preview
27 * Implements hook_fontyourface_view().
29 function fontsquirrel_fontyourface_view($font, $text) {
31 $metadata = unserialize($font->metadata
);
33 $output = '<div><img src="http://www.fontsquirrel.com/utils/makeFont.php?font=' .
$metadata['id'] .
'/' .
$metadata['font_filename'] .
'&width=800&size=14&text=' .
urlencode($text) .
'" /></div>';
35 $output .
= '<div><img src="http://www.fontsquirrel.com/utils/makeSolotypeSample.php?font=' .
$metadata['id'] .
'/' .
$metadata['font_filename'] .
'&case=all" /></div>';
39 } // fontsquirrel_fontyourface_preview
42 * Implements template_preprocess_page().
44 function fontsquirrel_preprocess_page(&$vars) {
46 if (!empty($vars['fontyourface']) && $_GET['q'] != 'admin/build/themes/fontyourface/add') {
50 foreach ($vars['fontyourface'] as
$used_font) {
52 if ($used_font->provider
== 'fontsquirrel') {
53 $metadata = unserialize($used_font->metadata
);
54 $paths[] = $metadata['path'];
59 if (count($paths) > 0) {
61 foreach ($paths as
$path) {
63 fontyourface_add_css_in_preprocess($vars, file_directory_path() .
'/fontyourface/fontsquirrel/' .
$path .
'-fontfacekit/stylesheet.css');
71 } // fontsquirrel_preprocess_page
74 * Implements hook_fontyourface_enable().
76 function fontsquirrel_fontyourface_enable($font) {
79 $metadata = unserialize($font->metadata
);
81 if ($font->css_family
== '') {
83 $api_result = drupal_http_request('http://www.fontsquirrel.com/api/familyinfo/' .
$metadata['path']);
85 if ($api_result->code
== '200') {
87 $decoded = json_decode($api_result->data
);
89 if (is_array($decoded) && is_object($decoded[0])) {
91 $font->css_family
= "'" .
$decoded[0]->{'fontface_name'} .
"'";
92 fontyourface_save_font($font);
97 drupal_set_message(t('There was an error importing font information for %fontname from Font Squirrel. Font not found in API.', array('%fontname' => $font->name
)), 'error');
105 drupal_set_message(t('There was an error importing font information for %fontname from Font Squirrel. API not responding.', array('%fontname' => $font-name
)), 'error');
112 $directory_location = dirname($_SERVER['SCRIPT_FILENAME']) .
'/' .
file_directory_path() .
'/fontyourface/fontsquirrel/' .
$metadata['path'] .
'-fontfacekit';
115 (!file_check_directory($directory_location))
118 $zip_location = dirname($_SERVER['SCRIPT_FILENAME']) .
'/' .
file_directory_path() .
'/fontyourface/fontsquirrel/' .
$metadata['path'] .
'-fontfacekit.zip';
120 // Download file .zip file
122 if (!file_exists($zip_location)) {
124 $kit_url = 'http://www.fontsquirrel.com/fontfacekit/' .
$metadata['path'];
126 $kit_result = drupal_http_request($kit_url);
128 if ($kit_result->code
== 200) {
130 // Save the .zip file
132 if (file_check_directory(dirname($zip_location), FILE_CREATE_DIRECTORY
)) {
134 file_save_data($kit_result->data
, $zip_location, FILE_EXISTS_REPLACE
);
139 drupal_set_message(t('There was an error saving font %fontname from Font Squirrel.', array('%fontname' => $font->name
)), 'error');
147 drupal_set_message(t('There was an error downloading font %fontname from Font Squirrel.', array('%fontname' => $font->name
)), 'error');
156 // Unzip the .zip file
158 if (function_exists('zip_open') && $zip = zip_open($zip_location)) {
160 file_check_directory($directory_location, FILE_CREATE_DIRECTORY
);
162 while ($entry = zip_read($zip)) {
164 if (zip_entry_open($zip, $entry, 'r') && ($zip_entry_filesize = zip_entry_filesize($entry))) {
166 $entry_name = zip_entry_name($entry);
167 $data = zip_entry_read($entry, $zip_entry_filesize);
168 file_save_data($data, $directory_location .
'/'.
$entry_name);
172 zip_entry_close($entry);
181 drupal_set_message(t('Unable to unzip font %fontname at <code>@zip_location</code>. See !zipdocs to enable unzipping, or unzip the file manually and enable this font again.', array(
182 '%fontname' => $font->name
,
183 '@zip_location' => $zip_location,
184 '!zipdocs' => l(t('PHP documentation on zip'), 'http://www.php.net/manual/en/zip.installation.php'),
193 fontyourface_disable_font($font);
200 } // fontsquirrel_fontyourface_enable
203 * Implements hook_fontyourface_import().
205 function fontsquirrel_fontyourface_import() {
207 $api_result = drupal_http_request('http://www.fontsquirrel.com/api/fontlist/all');
209 if ($api_result->code
== '200') {
211 $decoded = json_decode($api_result->data
);
213 foreach ($decoded as
$font_import) {
216 'id' => $font_import->id
,
217 'path' => $font_import->family_urlname
,
218 'font_filename' => $font_import->font_filename
,
221 $font = new StdClass
;
222 $font->name
= $font_import->family_name
;
223 $font->url
= 'http://www.fontsquirrel.com/fonts/' .
$font_import->family_urlname
;
224 $font->provider
= 'fontsquirrel';
225 $font->foundry
= $font_import->foundry_name
;
226 $font->foundry_url
= 'http://www.fontsquirrel.com/foundry/' .
$font_import->foundry_urlname
;
227 $font->license
= 'See Font Squirrel license page';
228 $font->license_url
= 'http://www.fontsquirrel.com/fonts/' .
$font_import->family_urlname .
'#eula';
229 $font->tags
= array($font_import->classification
);
230 $font->metadata
= serialize($metadata);
232 fontyourface_save_font($font);
238 } // fontsquirrel_fontyourface_import