You are here

function google_fonts_api_preprocess_page in @font-your-face 7

Same name and namespace in other branches
  1. 6.2 modules/google_fonts_api/google_fonts_api.module \google_fonts_api_preprocess_page()
  2. 6 modules/google_fonts_api/google_fonts_api.module \google_fonts_api_preprocess_page()

Implements template_preprocess_page().

File

modules/google_fonts_api/google_fonts_api.module, line 47

Code

function google_fonts_api_preprocess_page(&$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[$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];
        }
        else {
          $paths[$path_parts[0]][] = 'regular';
        }

        // else
      }

      // if
    }

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

      // foreach
      $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(',', $subsets);
      fontyourface_add_css_in_preprocess($vars, $url, 'remote');
    }

    // if
  }

  // if
}