You are here

function kernest_fontyourface_import in @font-your-face 7

Implements hook_fontyourface_import().

File

modules/kernest/kernest.module, line 18

Code

function kernest_fontyourface_import() {

  // KERNEST's Joyent server throws 500 error on Drupal's user agent
  $logging = variable_get('fontyourface_detailed_logging', FALSE);
  $api_result = drupal_http_request('http://kernest.com/styles/web-native.json', array(
    'headers' => array(
      'User-Agent' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3',
    ),
  ));
  if ($api_result->code == '200') {
    $decoded = json_decode(str_replace("\n", ' ', $api_result->data));
    if (is_array($decoded->fonts)) {
      foreach ($decoded->fonts as $import_font) {
        $font = new StdClass();
        $font->name = $import_font->name;
        $font->url = $import_font->url;
        $font->provider = 'kernest';
        $font->foundry = $import_font->foundry;
        $font->license = $import_font->license->name;
        $font->license_url = $import_font->license->url;
        $font->tags = array();
        $css = explode(';', $import_font->{'recommended css'});
        foreach ($css as $property) {
          if (strpos($property, ':') !== FALSE) {
            list($key, $value) = explode(':', $property);
            if (trim($key) == 'font-family') {
              $font->css_family = trim($value);
            }

            // if
            if (trim($key) == 'font-weight') {
              $font->css_weight = trim($value);
            }

            // if
            if (trim($key) == 'font-style') {
              $font->css_style = trim($value);
            }

            // if
          }

          // if
        }

        // foreach
        fontyourface_save_font($font);
      }

      // foreach
    }

    // if
  }
  elseif ($logging) {
    watchdog('@font-your-face', 'Invalid drupal_http_request response: @response', array(
      '@response' => print_r($api_result, TRUE),
    ), WATCHDOG_INFO);
  }

  // elseif
}