You are here

function google_fonts_api_preprocess_html in @font-your-face 7.2

Implements template_preprocess_html().

File

modules/google_fonts_api/google_fonts_api.module, line 57

Code

function google_fonts_api_preprocess_html(&$vars) {
  if (!empty($vars['fontyourface'])) {
    $paths = array();
    $subsets = array();
    foreach ($vars['fontyourface'] as $used_font) {
      if ($used_font->provider == 'google_fonts_api') {
        $metadata = unserialize($used_font->metadata);
        $path_parts = explode(':', $metadata['path']);
        $subsets[$path_parts[0]][$metadata['subset']] = $metadata['subset'];
        $all_subsets[$metadata['subset']] = $metadata['subset'];
        if (!isset($paths[$path_parts[0]])) {
          $paths[$path_parts[0]] = array();
        }

        // if
        if (count($path_parts) > 1) {
          $paths[$path_parts[0]][$path_parts[1]] = $path_parts[1];
        }
        else {
          $paths[$path_parts[0]]['regular'] = 'regular';
        }

        // else
      }

      // if
    }

    // foreach
    if (count($paths) > 0) {
      $families = array();
      foreach ($paths as $family => $variants) {
        $families[$family] = urlencode($family) . ':' . implode(',', $variants);
      }

      // foreach
      if (module_exists('google_webfont_loader_api')) {
        foreach ($families as $family => $family_with_variants) {
          $font_info = array(
            'name' => 'Google ' . $family,
            'google_families' => array(
              $family_with_variants . ':' . implode(',', $subsets[$family]),
            ),
          );
          _google_webfont_loader_api_load_font($font_info);
        }

        // foreach
      }
      else {
        $base = 'http://fonts.googleapis.com/css?family=';
        if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
          $base = 'https://fonts.googleapis.com/css?family=';
        }

        // if
        $url = $base . implode('|', $families) . '&subset=' . implode(',', $all_subsets);
        fontyourface_add_css_in_preprocess($vars, $url, 'remote');
      }

      // else
    }

    // if
  }

  // if
}