You are here

function local_fonts_update_7200 in @font-your-face 7.2

Update local fonts metadata.

File

modules/local_fonts/local_fonts.install, line 34
Removes fonts on disable.

Code

function local_fonts_update_7200() {
  $fonts = fontyourface_get_fonts($where = "provider = 'local_fonts'");
  if (!$fonts) {
    return NULL;
  }
  foreach ($fonts as $font) {
    $metadata = unserialize($font->metadata);
    if (isset($metadata['font_uri'])) {
      unset($metadata['font_uri']);
    }
    $dirname = drupal_dirname($metadata['path']);
    if ($handle = opendir($dirname)) {
      while ($file_name = readdir($handle)) {
        if (preg_match("/\\.ttf/i", $file_name) == 1) {
          $metadata['font_uri']['truetype'] = $dirname . '/' . $file_name;
        }
        if (preg_match("/\\.eot/i", $file_name) == 1) {
          $metadata['font_uri']['eot'] = $dirname . '/' . $file_name;
        }
        if (preg_match("/\\.woff/i", $file_name) == 1) {
          $metadata['font_uri']['woff'] = $dirname . '/' . $file_name;
        }
        if (preg_match("/\\.svg/i", $file_name) == 1) {
          $metadata['font_uri']['svg'] = $dirname . '/' . $file_name;
        }
      }
      closedir($handle);
    }
    $font->metadata = serialize($metadata);
    fontyourface_save_font($font);
  }
}