You are here

function google_fonts_init in Google Fonts 7

Same name and namespace in other branches
  1. 6.2 google_fonts.module \google_fonts_init()
  2. 7.2 google_fonts.module \google_fonts_init()

Implements hook_init().

File

./google_fonts.module, line 40
This module enables Google Fonts on your website.

Code

function google_fonts_init() {

  // Check if Google Fonts array has been converted yet
  $google_fonts_version = db_query("SELECT schema_version FROM {system} WHERE name = :name", array(
    ':name' => 'google_fonts',
  ))
    ->fetchField();
  if ($google_fonts_version < 7100 && user_access('administer software updates')) {
    drupal_set_message(t('You need to run the <a href="@link">update script</a> to perform required database updates.', array(
      '@link' => url('update.php'),
    )), 'error');
    return;
  }

  // We don't need to load the fonts twice as the admin interface
  // loads ALL fonts by default already
  if ($_GET['q'] == 'admin/config/system/google_fonts') {
    return;
  }
  $fonts_to_load = array();
  $enabled_fonts = variable_get('google_fonts_enabled_fonts', array());
  _google_fonts_add_custom_css();
  foreach ($enabled_fonts as $font) {
    $variants = isset($font['variants']) ? $font['variants'] : NULL;
    $subsets = isset($font['subsets']) ? $font['subsets'] : NULL;
    $fonts_to_load[] = _google_fonts_family_pathname($font['family'], $variants, $subsets);
  }
  if (!empty($fonts_to_load)) {
    _google_fonts_load_css($fonts_to_load, 1);
  }
}