You are here

function fontyourface_save_font in @font-your-face 6.2

Same name and namespace in other branches
  1. 8.3 fontyourface.module \fontyourface_save_font()
  2. 7.2 fontyourface.module \fontyourface_save_font()
  3. 7 fontyourface.module \fontyourface_save_font()

Adds or updates font, depending on whether it already exists.

9 calls to fontyourface_save_font()
common_fonts_fontyourface_import in modules/common_fonts/common_fonts.module
Implements hook_fontyourface_import().
fontdeck_fontyourface_import in modules/fontdeck/fontdeck.module
Implements hook_fontyourface_import().
fontsquirrel_fontyourface_enable in modules/fontsquirrel/fontsquirrel.module
Implements hook_fontyourface_enable().
fontsquirrel_fontyourface_import in modules/fontsquirrel/fontsquirrel.module
Implements hook_fontyourface_import().
fonts_com_fontyourface_import in modules/fonts_com/fonts_com.module
Implements hook_fontyourface_import().

... See full list

File

./fontyourface.module, line 923

Code

function fontyourface_save_font(&$font) {
  if (isset($font->tags)) {
    $tags = $font->tags;
  }
  else {
    $tags = array();
  }

  // else
  unset($font->tags);
  if (isset($font->old_url)) {
    $exists = db_fetch_object(db_query("SELECT fid FROM {fontyourface_font} WHERE (url = '%s' OR url = '%s') AND provider = '%s'", $font->url, $font->old_url, $font->provider));
  }
  else {
    $exists = db_fetch_object(db_query("SELECT fid FROM {fontyourface_font} WHERE url = '%s' AND provider = '%s'", $font->url, $font->provider));
  }

  // else
  if ($exists) {
    $existing_font = fontyourface_get_font($exists->fid);
    $font->fid = $existing_font->fid;

    // Keep status, selector, and tags the same.
    $font->enabled = $existing_font->enabled;
    $font->css_selector = $existing_font->css_selector;
    fontyourface_add_font_tags($font);
    drupal_write_record('fontyourface_font', $font, 'fid');
  }
  else {
    drupal_write_record('fontyourface_font', $font);
  }

  // else
  db_query('DELETE FROM {fontyourface_tag_font} WHERE fid = %d', $font->fid);
  if (!is_array($tags)) {
    $tags = array();
  }

  // if
  foreach ($tags as $tag) {
    $tag_object = new StdClass();
    $tag_object->name = $tag;
    fontyourface_save_tag($tag_object);
    $tag_font = new StdClass();
    $tag_font->tid = $tag_object->tid;
    $tag_font->fid = $font->fid;
    drupal_write_record('fontyourface_tag_font', $tag_font);
  }

  // forach
  $font->tags = $tags;
}