You are here

function _google_fonts_available_fonts in Google Fonts 7.2

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

Provides all needed details about Google fonts. Thanks at @sreynen to provide this array in his @font-your-face module

4 calls to _google_fonts_available_fonts()
google_fonts_admin_settings_form in ./google_fonts.admin.inc
Implements hook_admin_settings() for configuring the module
google_fonts_update_7100 in ./google_fonts.install
Change the google_fonts array of enabled fonts to the new format
_google_fonts_get_font_info in ./google_fonts.module
Return the path of this font If it is a child font of a larger family, scan the array to determine its path
_google_fonts_update_font_list in ./google_fonts.module
Trigger to reset the locally stored variable and fetch a new font list

File

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

Code

function _google_fonts_available_fonts($reset = FALSE) {
  $fontsbuffer = variable_get('google_fonts_webfonts', array());
  if (empty($fontsbuffer) || $reset) {

    // Return the JSON object with all available fonts
    // For now, it uses my (BarisW) API key
    // This key is limited to 10.000 requests per day, which should
    // be sufficient as it is only used when selecting fonts in the
    // admin interface. After that, it's cached in Drupal.
    $result = drupal_http_request('https://www.googleapis.com/webfonts/v1/webfonts?key=AIzaSyBgeqKlFdYj3Y7VwmrEXnXzpnx5TfKXG4o');
    if ($result->code != 200) {
      drupal_set_message(t('The list of Google Fonts could not be fetched. Verify that your server can connect the Google Servers (https://www.googleapis.com). Error: %error', array(
        '%error' => $result->error,
      )), 'error');
    }
    elseif (isset($result->data)) {
      $fontsbuffer = json_decode($result->data);
      variable_set('google_fonts_webfonts', $fontsbuffer->items);
    }
  }
  return $fontsbuffer;
}