You are here

function fontdeck_fontyourface_import in @font-your-face 7.2

Same name and namespace in other branches
  1. 6.2 modules/fontdeck/fontdeck.module \fontdeck_fontyourface_import()
  2. 7 modules/fontdeck/fontdeck.module \fontdeck_fontyourface_import()

Implements hook_fontyourface_import().

File

modules/fontdeck/fontdeck.module, line 23

Code

function fontdeck_fontyourface_import() {
  $success = TRUE;
  $project = variable_get('fontdeck_project', '');
  $domain = fontdeck_get_domain();
  $project_info_url = FONTDECK_BASE_URL . 'project-info?project=' . $project . '&domain=' . $domain;
  if ($project != '') {
    $response = drupal_http_request($project_info_url);
    if ($response->code == 200) {
      $data = json_decode($response->data);
      if (isset($data->error)) {
        drupal_set_message($data->error, 'error');
        return;
      }
      $fontdeck_css = variable_get('fontdeck_css', array());
      if (!isset($fontdeck_css[$project])) {
        $fontdeck_css[$project] = array();
      }

      // if
      $fontdeck_css[$project][$domain] = $data->css;
      variable_set('fontdeck_css', $fontdeck_css);
      foreach ($data->provides as $import_font) {
        $font = new StdClass();
        $font->name = $import_font->name;
        $font->url = 'http://fontdeck.com/search?q=' . urlencode($import_font->name);
        $font->provider = 'fontdeck';
        $font->tags = array();
        $font->css_family = $import_font->name;
        $font->css_style = $import_font->style;
        $font->css_weight = $import_font->weight;
        fontyourface_save_font($font);
      }

      // foreach
    }
    else {
      $success = FALSE;
      drupal_set_message(t('There was an error importing font information for project @project on this domain (@domain) from Fontdeck.', array(
        '@project' => $project,
        '@domain' => $domain,
      )), 'error');
    }

    // else
  }
  else {
    $success = FALSE;
    drupal_set_message(t('Missing project number to import.'), 'error');
  }

  // else
  return $success;
}